<<

Commands January 2003 Unix

This quick reference lists commands, including a syntax diagram 2. Commands and brief description. […] indicates an optional part of the 2.1. -line Special Characters command. For detail, use: Quotes and Escape man command Words "…" Use man tcsh for the command language. Suppress Filename, Variable Substitution '…' Escape Character \ 1. Files Separation, Continuation 1.1. Filename Substitution Command Separation ; Wild Cards ? * Command-Line Continuation ( end of line) \ Character Class ( is any single character) [c…] 2.2. I/O and Pipes Range [c-c] Home Directory ~ Standard Output > Home Directory of Another User ~user (overwrite if exists) >! List Files in Current Directory [-l] Appending to Standard Output >> List Hidden Files ls -[l]a Standard Input < Standard Error and Output >& 1.2. Manipulation Standard Error Separately Display File Contents filename ( command > output ) >& errorfile Copy source destination Pipes/ Pipelines command | [ | filter] Move (Rename) oldname newname Filters Remove (Delete) filename Word/Line Count [-l] Create or Modify file pico filename Last n Lines [-n] lines sort [-n] 1.3. File Properties Multicolumn Output -t Seeing Permissions filename ls -l List Spelling Errors ispell Changing Permissions nnn filename chmod c=p…[,c=p…] filename 2.3. Searching with n, a digit from 0 to 7, sets the access level for the user grep Command grep "pattern" filename (owner), group, and others (public), respectively. c is one of: command | grep "pattern" u–user; g–group, o–others, or a–all. p is one of: –read Search Patterns access, access, or x–execute access. beginning of line ^ Setting Default Permissions ugo end of line $ ugo is a (3-digit) number. Each digit restricts the default any single character . permissions for the user, group, and others, respectively. single character in list or range […] Changing Modification filename character not in list or range [^…] Making Links [-s] oldname newname zero or more of preceding char. or pattern * Seeing File Types ls -F zero or more of any character .* 1.4. Displaying a File with escapes special meaning \

Run ilename less less f 3. C- Features. Next line RETURN 3.1 Substitution Next Page SPACE Previous line k Repeat Previous Command !! Previous Page b Commands Beginning with str !str Commands Containing str !?str[?] 1.5. Directories All Arguments to Prev. Command !* Change Directory directory Word Designators New Directory directory All Arguments :* Remove Directory directory Last Argument :$ Print Working (Show Current) Directory First Argument :^ n'th Argument :n Arguments x Through y :x-y Standard Commands file Modifiers Aliases and Commands command Print Command Line :p Describe Command whatis command Substitute Command Line :[g]s/l/r/ Searching Out Files dir -name name -print dir is a directory name within which to search. 3.2 Aliases name is a filename to search for. Command alias name 'definition' 6.2. Finding Changes definition can contain escaped history substitution event and Comparing Files leftfile rightfile word designators as placeholders for command-line arguments. diff prefixes a less-than (<) to selected lines from leftfile and a greater-than (>) to lines from rightfile. 3.3. Variable Substitution 6.3. Automating Tasks Creating a Variable set var Assigning a Value set var = value Create a Makefile pico Makefile Expressing a Value $var A makefile consists of macro definitions and targets. Displaying a Value $var Makefile make -n [target] value is a single word, an expression in quotes, or an Run make make [target] expression that results in a single word after variable, 6.4. Managing Disk Usage filename and command substitution takes place. Assigning a List set var = (list) Check Quota quota -v list is a space-separated list of words, or an expression that Seeing Disk Usage results in a space-separated list. -s Selecting the n'th Item $var[n] 6.5. Combining and Compressing Files Selecting all Items $var Create a tarfile file file1 file2 … fileN Selecting a Range $var[x-y] tar cf .tar tar combines files but does not Item Count $#var Create a zipfile zip filename 3.4 foreach Lists Unzip a file unzip filename Start foreach Loop foreach var (list) 7. Printing foreach prompts for commands to repeat for each item in list (with >), until you end. Within the loop, $var 7.1 Formatting Output for Printing stands for the current item in list. Paginate with Page Headers pr filename in n columns pr -n filename 3.5. Command Substitution Format for Laser Printer tex document Replace Command with its Output on Command Line `…` 7.2 The Printer Queue 3.6 Print a File lp [-dpr] filename Run Command in the Background & lpcae filename Stop Foreground Job CTRL-Z Check Quota lpquot List of Background Jobs jobs List Queue lpq Bring Job Forward %[n] Stop Job lprm Resume Job in Background %[n] & 8. Miscellaneous 4. Processes 8.1 Miscellaneous Commands Listing [-[ef]] List Commands for Subject subject Terminating [-9] PID man -k Display Current Date and Time Timing time command date time is a number up to 4 digits. script is the name of a file Log off containing the command line(s) to perform. Electronic pine Display Documentation man command 5. Users 8.2 Control Keys Seeing is Logged In who Abort Program CTRL-C w Backspace (Delete Last Character) CTRL-H Seeing Your User Name Pause Display on Screen CTRL-S

Resume Display after CTRL-S CTRL-Q 6. Managing Files Send Job to Background CTRL-Z followed by bg 6.1. Looking Up Files

Is this document ? Is it missing crucial information? Please mail comments to the handout editor, CAE, 1410 Engineering Drive, or to: [email protected]