Friday, April 21, 2017

Basic linux commands

I this blog post i am going to write some basic Linux command that every Linux user should know :

but before digging in to the commands it is important that we know about the basic directory structure of Linux OS . following article has the details linux-directory-structure-explained


1. pwd2. ls3. cd4.cp5. rm6. mkdir7. rmdir8.clear9. man command10. Check current OS version 11. Check memory usage12. Create an empty file (touch command)13. Which (shows the installation path of a program or command)14. Search text in a file (grep command)15. Zip a directory16.UnZip a directory




1. pwd
The first command i am going to talk about is "pwd" . pwd command stand for "print working directory". so if i write pwd in a terminal and press enter it will show which directory i am currently located at.


As you can see i am currently located at centos directory which is insdse root home directory.

2. ls
The second command I want to show you is the  "ls" command. ls stand for list. 
as you can see above the "pwd" shows where i am currently in and the ls command shows what i have inside my current directory.

 

so as you can see , inside my current working directory  i have the following item Desktop, Documents, Downloads, Music, Pictures, Public, Templates and Videos.

3. cd
The next command I want to show is "cd" command . cd stands for change directory. cd is a navigational command. so let's i want to go to the "Downloads" folder. how do i do that ? i have use cd command . 




4.cp
cp stand for copy. I can use the cp command to copy file or directory and past it to another directory


5. rm
rm stands for remove. i can use rm command to remove an file or directory.

6. mkdir
mkdir stands for make directory. i can use the mkdir command to create a new directory.

7. rmdir
rmdir stands for remove directory. i can use the rmdir command to remove a directory. one thing to remember here is if we can something inside the directory I can not remove the directory using the rmdir command. i that case i have to use rm command 

rm -r mydirectory

8.clear
clear command clear the terminal screen.


9. man command
man stand for manuals

10. Check current OS version 
using the following two commands we can check current OS info .
$ uname -a

$ cat /etc/*release*

11. Check memory usage

The free command is the most simple and easy to use command to check memory usage on linux . Here is a quick example:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          7976       6459       1517          0        865       2248
-/+ buffers/cache:       3344       4631
Swap:         1951          0       1951

The m option displays all data in MBs. The total os 7976 MB is the total amount of RAM installed on the system, that is 8GB. The used column shows the amount of RAM that has been used by linux, in this case around 6.4 GB. The output is pretty self explanatory. The catch over here is the cached and buffers column. The second line tells that 4.6 GB is free. This is the free memory in first line added with the buffers and cached amount of memory.

Linux has the habit of caching lots of things for faster performance, so that memory can be freed and used if needed.
The last line is the swap memory, which in this case is lying entirely free.

12. Create an empty file (touch command)

One easy way to create an empty file is with touch.
touch my_file_name.txt 

The above command will create a file with the name my_file_name.txt 

13. Which (shows the installation path of a program or command)

[centos@localost ~]$ which git
/usr/bin/git

The above command shows the installation location of git.

14. Search text in a file (grep command)

15. $ zip -r myfiles.zip mydir

16. unzip myzip.zip

$  grep "text_to_search" filename




More usefull command can be found here





No comments:

Post a Comment

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...