Objective: Introduction to Common Linux Commands.
- man
This command shows the manual pages of the commands, which lists the detail description of the specified command.
e.g.
man ls
- help
This command shows the description about the particular commands.
File and Directory manipulation Commands
- ls
ls command brings about a lot to discuss. Simple ls command shows the content of your current directory.
- ls -a
To list all of the entries (hidden files) of a directory you would use the
–a option. Files that begin with the “.” And “..” are called Parent and Childs simultaneously and also called hidden files and are not usually listed with ls.
Further Option to the ls command are as follows:
-d list the name of the current directory
-F show directories with a trailing ‘/’
executable files with a trailing ‘*’
-g show group ownership of file in long listing
-i print the inode number of each file
-l long listing giving details about files and directories
-R list all subdirectories encountered
-t sort by time modified instead of name
Exercise – 1
Test all these options with ls command; also make use of man command.
- mkdir
This command is used to create a directory in your present working directory.
e.g.
mkdir directoryname
- touch
This command is used to create a file.
e.g.
touch filename
- cat
This command is used to display the file content.
e.g.
cat filename(s)
- cat > filename
This option is used with cat command to create a new file as well as putting some data in it. By first entering this command you are pointed to give input and u can terminate the inputting of data by pressing ctrl+ d.
- cat >> filename
use this option to append some data in the created file.
- more
The command will display the file content at same time.
e.g.
more filename
- less
The command is also used to display the file content, but it display step by step.
e.g.
less filename
- head
This command is used to show the specified number of lines of the file from starting of the file.
e.g.
head –5 filename
it will display the first five lines of the file.
- tail
It will display the number of lines from the end of the file.
e.g.
tail –3 filename
- wc
The command is used to count the file content.
e.g.
wc –l filename
It will display the number of lines in the file.
Further options are as follows.
wc –w filename
wc –l filename
wc –c filename
Exercise – 2
Test the above options with wc command by first creating the file and also read its description by man command.
- grep
To extract the specified sentence from the file.
e.g.
grep “abc” filename
- grep [ab]cd filename
This format with the grep command is used to show all words starting with ‘a’ and ‘b’ with the combination of “cd”.
e.g.
grep [cr] an filename
This will extract the word “can” and “ran” from the file.
Exercise – 3
Create a file put some data in it and test this option and observe the output.
Exercise – 4
Test the option grep –n, first read its description by man command.
- cd
The command is used to change the directory from the presenting working directory
e.g.
cd filename
- cd..
The short hand command to go to the last working directory.
- mv
This command is used to move the directory/file from one directory to another.
e.g.
mv sourceDir destinationDir
- rmdir
To remove the directory.
e.g.
rmdir directoryname
- rm
This command is used to delete the file from the present working directory, a number of files can be deleted simultaneously.
e.g.
rm filename1 filename2………..
- cp
The cp (copy) command is used to copy a file.
e.g.
cp filename1 filename2
- · cmp
This command is used to compare the two files(text or binary) byte by byte and display first occurrence where the file differs.
e.g.
cmp filename1 filename2
Exercise – 5
Create two file put some data in it and test the cmp command and observe the output.
- pwd
This command shows the present working directory.
- home
This command shows user’s home directory.