Friday, August 21, 2020

UNIX SHELL COMMAND & PIPELINING PART 3



In this article we discuss about some basic command of UNIX.These commands are very useful for operating or managing UNIX file system.

 Command 1: $ pg filename

Command is used to display constant page wise 

Example : $ pg +2  ab1

here ,  +2 for display next two pages

            -3 for display previous three pages

             q for quit


 Command 2: $ head  -n filename

 Command is used to display from header

where , n is any integer

Example : $ head -10 abc

Detail      : It will display 10 lines from header (Top)


 Command 3: $ tail  -n filename

 Command is used to display from tail (Bottom)

where , n is any integer

Example : $ tail -10  abc

Detail      : It display 10 line from bottom


 Command 4: $ file  file(s)

 Command is used to show file type.

Example : $ file  *

Detail      : Display all type of files    *|All


 Command 5: $ grep  option  string  file(s)

 Command is used for filter

Example : $ grep  amit  *

Detail      : Search amit in current directory

Example : $ grep  " Shailu"  ab*

                : $ grep  -in   amit   ab2

Detail     : where   -in  -optional [ignore] , amit - string   , ab2 - filename


CONCEPT:

If we want to run more than one command in one statement then we use pipeline concept. In pipeline output of one pipe is input of another pipe. It is represented by ( | ).

 Command 6: $ who | wc -l

Command first display all login / active users than count number of user.

Example:



 Command 7: $ who | grep   amit  |  wc  -l

 Command first display all login / active users than search 'amit' user and than count number of 'amit' user.

Example:




 Command 8: $ who | grep amit  >  aa

 Command first display all login / active users than search user name 'amit' and than save / copy it in 'aa' file.


 Command 9: $ who | grep amit | tee  aa  | wc  -l

 When we apply two operation in same field than we use tee command , like here 'amit' is save in 'aa' and also find number of 'amit ''.



 Command 10: $ file  * .c | wc  -l

Command first search those file name whose extension is ( .c ) and then show how many number of file of ( .c ) extension.


 Command 11: $ ls  -l  *c | wc  -l

 Command is used to show file.


 Command 12: If  we have any file abc and we don't know how many lines in that file and we want to display the constant of line number 26 to 75 than write the command.

$ head  -75 abc | tail -49 abc

 



 Command 13: $ PS

 Command is used to show how many process are running.

Example : command will show output such as

       PID                                   PPID                                           

 (ProcessId)                  Parent ProcessId                Terminal              Command

     3128                                 2456                                 tt02                           sh

     4132                                 4562                                 tt05                           ps

     5235                                 5632                                 tt03                          who

        -                                        -                                       -                                -                              


Note: SYSTEM CALLS
 fork ( )  :  Used to creating a process in memory
 Exet ( )  : Used to terminate any process
 Exec ( )  : Used to execute any process
 wait ( )   : wait

 Command 14: $ kill  -9  processno

This command is used  for forcefully termination.


No comments:

Post a Comment