Friday, July 31, 2020

UNIX SHELL COMMAND - PART 2



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: $ data

Command display date / time  (only admin can change this time / date)



Command 2:  $ cal  month  year

Note: Month will be (1 - 12)  | Year will be (1 - 9999)

Example: 
                $ cal  1998        Display calendar of 1998       
                $ cal  9 2005     Display calendar of September 2005    
                $ cal  1752        Basic Year / Starting Year
                $ cal  9 1752     Basic Year / Starting Year   


Command 3: $ cat > filename

Used to create a new file

Example:

               $ cat  > a1    File is created named a1.




Command 4: $ cat filename

Display content of file

Example:

               $ cat a1    Display content of file a1



Command 5: $ sort  -r  filename

Used for sorting ,  -r show reverse order sorting

Example:

             $ sort  -r  a1         (sort   by Z to A)  Descending order

             $ sort a1               (sort by A to Z)   Ascending order



Command 6: $ sort a1 > a1

Output of a1 redirect to a1 file



Command 7: $ cat a1

Display content of a1 file



Command 8: $ cat a1  a2

Display content of a1 file  & a2 file



Command 9: $ cat a1  >  a2

Used to copy a1 file to a2 file    i.e. (a1=a2)



Command 10: $ cat a1  a2 >  a3

Used to copy a1 and a2 into a3 file   i.e (a3 = a1 + a2)



Command 11: $ cat a1 , a2 >> a3

Used to append content of a3 file  i.e (a3 = a1 + a2 + a3)

Example:

                $ cat a2 , a1 >> a3

                $ cat a1 , a2 >> a2

                $ cat a1 >> a2



Command 12: $ man command name

Used to show online help

Example: 

                $ man who



Command 13: $ mkdir

Used for creating new directory.


Note : Unix use round robin algorithm for scheduling it is also known as time sharing.

Example : 

 If there are three process


In the above diagram first time slice is provide to a than b and than c this is also known as context switching.In this mechanism scheduler is any software who schedule the process. These scheduling process come in priority queue.

Note : Let we understand about directory in UNIX


Above represent the simple directory tree which represent root from root to current user.It is an pictorial representation. It is like  ( . /. . / jay / T3)
Here ,
             ( . ) means       / user / jay    (current directory)
             ( . . ) means     / user             (Parent directory)
Note: Parent of root directory is root. By default , we always start with current directory


Command 14: $ cd  directory name

Used for changing directory.

Example:

                $ cd T3

                $ cd . / T3

                $ cd  / user / jay / T3

                $ cd . . / . . / user / jay / T3

                $ cd . / jay / T3

                $ cd . . / user / jay / T3

                $ cd . . /. . /. . / user / jay / T3

                $ cd  . / . . / jay / T3

Note : All above commands are same regarding changing directory.



Command 15: $ cp  Source file    Target file

Used for copy any file from source directory to destination directory.

Example:

               $ cp     / user / jay / T1      / user / jay / T3 / m   [OR]    $ cp    . . / T1     . / m

         



Command 16: $ mv  Source file    Target file

Used for move or rename file source to target.

Example:

               $ mv     / user / jay / T1      / user / jay / T3 / m   [OR]    $ mv    . . / T1     . / T3 / m



Command 17: $ rmdir  Directory Name

Used for removing directory.

Example:

                $ rmdir T3


Command 17: $ rm  file(s)

Used for removing files.

Example: 

               $ rm  m        (It will remove m from jay directory by searching)

Note :

             $ rm *  ( For matching with all )

             $ rm * . *  ( For removing all files )



Command 18: $ rm  -i   ab*

ab* means file name start with ab and end with any.

-i  If we write -i than it will ask (are you sure [Y , N])


Command 19: $ rm  -r   Directory Name

-r is used for deleting directory

Example:

            $ rm -r T3    This command will delete whole tree of T3.





Command 20: $ wc  -lwc   File Name

Used for forward counting

l -   Line

w - Word

c -  Char

Example:

                $ wc -lwc ab1             Output like : 5  6  52   ( line=5, word=6, char=52)

                $ wc  -l  ab1                Output like : 5    ( line=5)

                $ wc  -wl  ab1             Output like : 6  5  ( word=6, line=5)















No comments:

Post a Comment