UNIX Commands ||General Features of UNIX commands||Command Structure||Commands of UNIX

  General Features of UNIX commands/ Command Structure:




Command Structure:

A UNIX command is an action request given to the UNIX shell for execution. The simplest commands are a single line entered at the command line prompt that cause a program or shell script to be executed.  

Command Syntax: the general format or syntax of a command is shown below:

fig. command syntax

 Verb: 

          The Verb is the command name. The command indicates what action is to be taken  Command name and options/arguments have to be separated by spaces or tabs to enable the system to interpret them as words. Single or multiple spaces can be given to separate the commands and options/arguments. 
      
Ex:  
$ cat       README 

 The Shell compresses these multiple spaces to a single space

Options: 

The Option modifies how the action is applied. For example, when we display the date, we can use an option to specify if we want the time in GMT or local time.  Options are usually one character preceded by a minus sign or plus sign. 

 Ex:
   $ wc -c filename    

          -w is the option to the command wc (-w indicate character count). 

 Options can normally be combined with only one – sign, i.e.,
 instead of using 
   
    $ wc  –c –w filename    
 
You might as well
          $ wc –cw filename    
 
To obtain the same output.

Arguments: 

The Arguments provide additional information to the command.
For example, when displaying the contents the of a file, an argument can be used to specify the file name. Some commands may accept single argument, some may accept multiple arguments and some commands may not accept any arguments.

Ex: 
                                $ wc abc def xyz   

           Where abc, def and xyz are the filename arguments to the command wc.

Basic Unix Commands : 

 echo: (Displaying a message )

The echo command copies its arguments back to the terminal.

Example1: displaying a message
                                 
      $ echo Hello World    
  Hello World


       $ echo “Error 105: Invalid Total Sales”    
     Error 105: Invalid Total Sales 
      $_

Example 2: displaying a message in multiple lines; 
              This can be achieved by specifying the message to printed with double quotes (“ “), when [Enter] is pressed, secondary prompt will be shown (>).  

                               $ echo  “UNIX  
                               > Linux
                               > Ubuntu “
                                  UNIX 
                                  Linux 
                                  Ubuntu
                                   $ _                  

 printf: An alternate to echo :

                               The printf command is an alternate to echo and performs the similar operation performed by echo command. Unlike echo it doesn’t automatically insert a newline unless the \n is used explicitly.
 
Example 1

    $ printf “ No filename Entered”  
 
    No filename Entered $_
                        
                         (Note: quotes are not mandatory, but it’s a good discipline to use them)

Example 2: 

 $ printf “No filename Entered \n”     
  No filename Entered $_

 ls: Listing Directory Contents:

ls command lists all filenames in the current directory.  The filenames in the current directory is arranged in ASCII collating sequence (numbers first, uppercase and then lowercase), with one filename in each line. 

Example 1:
                                     
                                         $ ls               
                                            08_packets.html 
                                         TOC.sh 
                                         calendar 
                                         dept.lst 
  • Directories often contain many files, and you may simply be interested in only knowing whether a particular file(s) is available. In that case, just use ls with the filename(s). 
  • If the file isn’t available, then the system will display the appropriate message.
 Example 2: 
                                        $ ls calendar 
                                         calendar

                                         $ ls perl
            Perl: No such file or directory.

 who: Who are the users ?

UNIX maintains an account of all users who are logged on to the system. The who command displays an informative listing of these users: 

Example 1:

                          

  • The first column shows the usernames (or user-ids) of five users currently working in the system
  • The second column shows the device names of their respective terminals. The third, fourth and fifth columns show the date and time of logging in, the last column shows the machine name from where the user has logged in. 
 The –H option prints the column headers, when combined with the –u option, provides a more detailed list.

  Example 2

                    
  •  The first five columns are the same as before, the sixth one represent the IDLE TIME, which           indicate how long it has been since there was any activity on the line.
  •   If the IDLE time is 0:48, it indicates that the user has no activity since 0 hours and 48 minutes. 
  •   If the IDLE time is . (dot) it indicates that the user has something in the last minute. 
  •   If the IDLE time is old it indicates that the user had no activity over 24 hours. 
  •  The seventh column shows the process id (PID) of the process 

 date : Displaying the system date 

  You can display the current date with the date command, which shows the date and time to the nearest second. 
 
Example 1:

                          
           The command can be used with –u option to display the Greenwich Mean Time (GMT): 

 Example 2: 

                           

  • The command can be used with suitable format specifiers as arguments. Each format is preceded by the + symbol, followed by the % operator, and a single character describing the format (format code).  

The list of all the format specifiers is shown in the table below.

                                                             

 cal: The Calendar :

 The calendar command, cal, displays the calendar for a specified month or for a year.

 The general format of cal command is shown below: 

               cal [     [ month ]   year ]   

 Everything within rectangular brackets is optional, cal can be used without arguments, in which case it displays the calendar of the current month:


                                         
 
The syntax also tells us that when cal is used with arguments, the month is optional but the year is not. 

For example to see the calendar for the month of March 2006, you need two arguments: 

 
                                          

passwd : Changing your password 

                   The user password can be changed with the passwd command. passwd command expects the user to respond three times. First, it prompts for the old password. Next, it checks whether you have entered a valid password, and if you have, it then prompts for the new password, finally the command asks you to reenter the new password.  When you enter the password, the string is encrypted by the system.


you can learn here THANK YOU .........for visiting for more info  CONTECT



COMPUTER NETWORK : introduction    TOPOLOGIES  Network types




Previous Post Next Post

Contact Form