Lab 3

For each of the following commands write a description of what it does and provide a screenshot with an example of its usage:


>: used to redirect output from stdout.

gm1

 

When typing the command ‘ls -l /usr/bin > ls-output.txt”, nothing will appear on the terminal screen. However,when you check your home folder. you will notice that a text file named ‘ls-output.txt.’ is created.

gm2

 

The file ‘ls-output.txt’ contains information from the bin folder.

 

 

 

 

gm3

 


<: used to redirect input.

When you type the command ‘cat<ls-output.txt”, the text on the file will display on the terminal screen. The command ‘cat’ is used to read a file.

gm4


|allows you to redirect the output of one command and pipe it as input to another.

On the terminal screen, type the following: ‘ ls -l /bin/usr | less’.

gm5


grep: used to search text or searches the given file for lines containing a match to the given strings or words.

The following is the text in the file ‘gm’.

gm9

 

When you type the command, grep ‘0’ gm, all the lines containing the number ‘0’ will appear in the terminal screen.

gm10


head: prints the first 10 lines of a file.

gm7

The picture above is the text inside the file ‘gm’. on the terminal screen, when you type ‘head gm’, the first ten numbers in the file gm will appear on the terminal screen.

gm6


tail: prints the last 10 lines of a file.

gm7

 

The picture above is the text inside the file ‘gm’. on the terminal screen, when you type ‘tail gm’, the last ten numbers in the file gm will appear on the terminal screen.

gm6

 


echo: command used to display a line of text.

command ‘echo gm’ will display gm.

command ‘echo ls-output.txt’ will display ls-putput.txt.

command ‘echo $((2+2))’ in other word 2+2 will display 4 on the terminal screen.

command ‘echo $(($5**2)) * 3)) in other word (5^2)*3 will display 75 on the terminal screen.

gm8