Objective: Introduction to Common Linux Commands.
This command shows the manual pages of the commands, which lists the detail description of the specified command.
This command shows the description about the particular commands.
File and Directory manipulation Commands
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.
This command is used to create a directory in your present working directory.
This command is used to create a file.
This command is used to display the file content.
- 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.
The command will display the file content at same time.
The command is also used to display the file content, but it display step by step.
This command is used to show the specified number of lines of the file from starting of the file.
head –5 filename
it will display the first five lines of the file.
It will display the number of lines from the end of the file.
tail –3 filename
The command is used to count the file content.
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.
To extract the specified sentence from the file.
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”.
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.
The command is used to change the directory from the presenting working directory
The short hand command to go to the last working directory.
This command is used to move the directory/file from one directory to another.
mv sourceDir destinationDir
To remove the directory.
This command is used to delete the file from the present working directory, a number of files can be deleted simultaneously.
rm filename1 filename2………..
The cp (copy) command is used to copy a file.
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.
cmp filename1 filename2
Exercise – 5
Create two file put some data in it and test the cmp command and observe the output.
This command shows the present working directory.
This command shows user’s home directory.