160 likes | 342 Views
Unix Comp-145. Chapter 2. Objectives. Unix Commands The Path Flexibility of Command Usage Access and Manipulate Files Command Classification Using man Several simple commands . UNIX Commands. who (lists who is on system) date (date and time)
E N D
Unix Comp-145 Chapter 2 BROOKDALE COMMUNITY COLLEGE
Objectives Unix Commands The Path Flexibility of Command Usage Access and Manipulate Files Command Classification Using man Several simple commands BROOKDALE COMMUNITY COLLEGE
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 – Terminate session
UNIX Commands Generally, 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 Internal 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 External 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) • Specifies a list of directories to search. • Shell looks at PATH only when • Command is not used with a pathname • Also not a shell built-in. • Command can still be executed if not in PATH by • Using a pathname. • Modifying PATH to include the directory containing the command. BROOKDALE COMMUNITY COLLEGE
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. BROOKDALE COMMUNITY COLLEGE
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 BROOKDALE COMMUNITY COLLEGE
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 & BROOKDALE COMMUNITY COLLEGE
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 BROOKDALE COMMUNITY COLLEGE
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). BROOKDALE COMMUNITY COLLEGE
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 passwdand man -s 5 passwd). BROOKDALE COMMUNITY COLLEGE
Using man (Cont’d) • man documentation not available for most internal commands of the shell. • Use manman first to know how man should be used. BROOKDALE COMMUNITY COLLEGE
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 -lware valid.) BROOKDALE COMMUNITY COLLEGE
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. BROOKDALE COMMUNITY COLLEGE
Several simple commands Example: prtSyntax/Synopsis prt [ -c| -m | -C ] [ -lw ] [ file ... ] Example: edSyntax/Synopsis ed[ file ... ] Example: lsSyntax/Synopsis ls [-OPTION] [fileName | substring] OPTION: -x= multi-column outut -F= prefix executables with *, directories with / and symbolic links with @ -a= shows all file names beginning with. Or .. -l= show long list -d= shows only dir names See pg 66 for complete options list. BROOKDALE COMMUNITY COLLEGE