7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE2 Objectives U NIX C OMMANDS T HE P ATH F LEXIBILITY OF C OMMAND U SAGE A CCESS AND M ANIPULATE F ILES C OMMAND C LASSIFICATION U SING MAN S EVERAL SIMPLE COMMANDS
UNIX Commands WHO ( LISTS WHO IS ON SYSTEM ) DATE ( DATE AND TIME ) MAN ( MANUAL PAGE FOR THE SPECIFIED COMMAND ) INFO - LIKE MAN ORGANIZED HIERARCHICALLY PASSWD ( CHANGE PASSWD ) SCRIPT - LOGS ALL INTERACTION IN A FILE CLEAR - CLEAR SCREEN TTY - TERMINAL ID STTY - TERMINAL OPTIONS EXIT – T ERMINATE SESSION
UNIX Commands G ENERALLY, COMMANDS ARE EXECUTABLE DISK FILES (C PROGRAMS ) – Commands execute like any other program (remember chp 1) – UNIX supports commands written in any language (ie Java) – Files do not need extension – Shell (exception) automatically invoked once you log in
Types of Commands I NTERNAL COMMAND OF THE SHELL WHICH COULD BE a built-in (like cd, pwd, etc.) an alias defined by the user that invokes the disk or E XTERNAL PROGRAM ON DISK WHICH COULD BE a binary executable (written in C, C++). a script file (like a shell or perl script). internal version in a specific manner.
The PATH A shell variable (or environment variable) o Specifies a list of directories to search. Shell looks at PATH only when o Command is not used with a pathname o Also not a shell built-in. Command can still be executed if not in PATH by o Using a pathname. o Modifying PATH to include the directory containing the command. 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE6
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE7 The PATH (Contd) PATH can be modified in an absolute or relative manner: PATH =/usr/bin:. (Absolute) PATH=$PATH:/usr/local/bin (Relative) Modified setting is lost after user has logged out unless saved in a startup file.
Flexibility of Command Usage Run multiple commands by specifying them in the same line: date ; echo $PATH Split a command into multiple lines: $ echo “Hello > Dolly” Save command output in a file: date > foo date | cut -d” “ -f2 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE8
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE9 Flexibility of Command Usage (Cont’d) Use output of one command as input of another: date | cut -d” “ -f2 Run a command in the background with &: ls -lRa / > $HOME/ls-lRa.txt &
Access and Manipulate Files ls - List directory content mv – Move file to another location or name cp - Create a copy of the named file in the current or different directory mkdir – Create a new directory as a child of the current directory rm – Remove the named file rmdir – Remove the named directory 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE10
Command Classification: A Different Approach Utilities that are generally used in standalone mode ( vi, stty, bc ). Commands that do useful work but produce no output ( mkdir, cp, rm ). Commands that produce output which may need further processing ( date, who, ls, tty, man, info ). Commands specially designed to accept output of other commands as their input and vice versa ( grep, sort, head, prt ). 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE11
Using man Displays documentation of commands, configuration files, system calls and library functions. Organized in a number of sections. Commands are found in Section 1. May need to use section number when entry exists in multiple sections (e.g. man passwd and man -s 5 passwd ). 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE12
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE13 Using man (Cont’d) man documentation not available for most internal commands of the shell. Use man man first to know how man should be used.
Understanding a man Page Example: wc Syntax/Synopsis wc [ -c | -m | -C ] [ -lw ] [ file... ] Most useful information available in SYNOPSIS and DESCRIPTION. When options grouped in [ ] without a |, one or more of them can be used. (-l, -w and -lw are valid.) 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE14
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE15 Understanding a man Page The | signifies an OR condition. (e.g., Only one of -c, -m or -C can be used.) The... means that multiple occurrences of the preceding item are possible. ( wc can be used with multiple files.) EXIT STATUS indicates values returned on error.
Several simple commands Example: prt Syntax/Synopsis prt [ -c | -m | -C ] [ -lw ] [ file... ] Example: ed Syntax/Synopsis ed [ file... ] Example: ls Syntax/Synopsis ls [-OPTION] [fileName | substring] OPTION: -x= multi-column outut -F= prefix executables with *, directories with / and symbolic links -a= shows all file names beginning with. Or.. -l= show long list -d= shows only dir names See pg 66 for complete options list. 7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE16