uname command, short for Unix Name, will print detailed
information about your Linux system hostname will give you hostname. hostname -i will give you ip of hostname. pwd (to check the present directory) ls (to view files in a directory) ls -l (to view files and additional information about each file) ls -a (will show you hidden files) mkdir New (to make directory with name New) cd New (to move inside directory New) cd .. to go back to the parent directory (one step back in directories) ‘OR’ cd - to go back to the parent directory (one step back in directories) cd will directly take you to the parent directory which is [root@sandbox ~] in our case. cd ../../.. or cd ../.. to go back three or two steps in directories respectively. Note: There is difference between [root@sandbox ~] and [root@sandbox /] [root@sandbox /] is starting point above [root@sandbox ~]
cd /root/One/Two to directly go from [root@sandbox /] to Two
directory. [root@sandbox /] is starting point [root@sandbox ~] is under [root@sandbox /] One is inside [root@sandbox ~] Two is inside One
clear to clear the current window
rmdir dir_name will remove the directory rm file_name will remove the file.
cp file.txt /root/One/Two copy file from current directory into
Two directory mv file.txt /root/Farhan/Qamar copy file from current directory into Two directory find /root/ -name one.txt to find file (one.txt) in directory root and its subdirectories. grep Ali first.txt to find word “Ali” in file first.txt. Crtl + z to come out of any process/command.
cat one.txt to read contents of file one.txt
less one.txt to read the contents of file one.txt, press q after reading head -n 5 one.txt to read top 5 lines of file one.txt tail -n 7 one.txt to read last 7 lines of file one.txt
To create new file in linux.
touch /root/One/Two/new.txt will create empty file new.txt in directory Two
To edit file in linux system.
vi one.txt press Esc followed by i to enter in insert mode.
Do changes in the file.
Press Esc followed by :wq! to quit save and quit file. Press Esc followed by :!q to exit without saving changes and press Enter. diff one.txt two.txt To find difference between two files.
echo my name is Ali >>new.txt
to move some of the text “my name is Ali” in file new.txt
man head this will tell (help) about the command head similarly about other commands.