Linux basic commands with examples
Today we are going to study some frequently use Linux basic commands with examples which are helpful for beginner and advanced level Linux admin and shell programmer.
Note: All Linux commands are case sensitive and must be typed in Lowercase Letter (a b,c…).
Below are the list of Linux basic commands with examples :
- pwd : Use to see Present Working Directory.
- cd : Use to Change Directory.
- mkdir : Use to Make Directory.
- rmdir : Use to Remove Directory (But Directory should be empty ).
- ls : Use to List out files and directory present inside the present directory.
- touch : Use to Create a new file.
- vi : Use to edit or modify file data also use to create new file as well.
- cat : Use to see file data in the same console / Windows.
- rm : Use to remove file.
- rm -r : Use to remove directory along with files and other directories which are inside.
Linux basic commands with examples
- Command : pwd
- Use to see Present Working Directory.
- In the below snap when we type “pwd” command in the console then we can able to see the present working directory of root user is “/root also “~” .To learn more about cd command, read: cd command in Linux
- Command: cd
- Use to Change Directory.
- In the below snap when we type “cd” command along with directory name ” T4Tution ” which is present in this directory (/root) then it will switch to T4Tution or /root/T4Tution directory from /root directory .
Below command, use to go back to multiple directory. As we can see before we are in “d3” directory and after the mentioned command “cd ./../../ ” executed we go back of two directories in “d1“.
- Command: mkdir
- Use to Make Directory.
- When we type “mkdir” along with directory name.
It creates a new directory as mentioned in a snap ” mkdir T4Tution “. mkdir commands create new directory “T4Tution” in /root.
In below snap when we type commands ” mkdir -p d1/d2/d3 “.
It creates directory and subdirectory at the same time, that means first it create d1 after that it create d2 inside d1 and d3 inside d2.
In above snap when we type command mkdir along with directories name as mentioned “mkdir dir1 dir2 dir3” in above snap then it creates multiple directories.
- Command: rmdir
“rmdir” use to remove /delete an empty directory.
- Command: ls
- Use to List out files and directory present inside a present directory.
- “ls” command list out all directory and file in given directory.
Below command ls -l” gives complete information about file and directory.
“ls -la” command display hidden files and directory.
- Command: touch
- Use to Create a new file.
- Below command “touch” along with file name used to create a new file.
We can create multiple files by using touch command as shown above.
- Command: vi
- Use to edit or modify file data also use to create a new file as well.
- Below command “vi” along with file name used to create a new file and to edit a file as well.
Once we have done with editing then we can save by :wq (w means to save and q means quite ).
- Command: cat
- Use to see file data in same console.Below command used to display data of a file.
- Command: rm
- Use to remove the file.
- rm command uses to remove file or files by user permission. “y” means yes and “n” means no.
When we try to execute above command, “rmdir d1″ then it will show error as we can see but when we execute “rm -r” then this command remove complete directory and file by user permission.