UNIX C Shell Cheat Sheet Directory Manipulation Creating Directories % mkdir directory Setup Changing Directories % cd directory Terminal Setup % stty erase ‘^?’ kill ‘^U’ intr ‘^C’ % cd % set term=vt100 Displaying Current % pwd Setting Path Variable % set path=(directory ... directory) Directory Password Changing % passwd Removing Directories % rmdir directory Changing Default % chsh Shell Miscellaneous Commands Help % man command % man -k topic Finding Files % find directory -name filename -print Logging Out % logout Searching Files % grep string filename % Sorting Files % sort [-o output-file] filename Comparing Files % diff filename1 filename2 File Manipulation % cmp filename1 filename2
Listing Files % ls Displaying Files % cat filename File Protection % more filename u file owner (u is short for user) next page User and Permission g group members next line Types o all other users q quit r Copying Files % cp file1 file2 read permission % cp file1 [file2] ... directory w write permission % cp -r directory1 directory2 x execute permission (for directories, allows users to use the directory name in a pathname) Use the -i option to prompt before overwriting files. Displaying File % ls -l filename Moving Files % mv file1 file2 Protection % mv file1 [file2] ... directory Changing File % chmod [ugo][+-=][rwx] filename % mv directory1 directory2 Protection % chmod nnn filename Use the -i option to prompt before overwriting files. numeric protection mode table % rm filename Removing Files user group other % rm -r directory r 400 40 4 Use the -i option to prompt before deleting files. w 200 20 2 x 100 10 1 Printing Files % lpr filename Default Protection % umask nnn The umask value is subtracted from 666 for new files and from 777 for new directories. I/O Redirection Special Files Input Redirection % command < filename .cshrc This file, if it exists in your home directory, is automatically % command > filename Output Redirection executed at login. Must begin with “#” to indicate C shell (overwrite) script. % command >> filename Output Redirection .cshrc typically includes C shell specific commands such (append) as the set noclobber, set history, set savehist, Error Redirection % command >& filename and alias commands. (overwrite) .login This file, if it exists in your home directory, is automatically # Error Redirection % command >>& filename executed at login. Must begin with “ ” to indicate C shell (append) script. .login Noclobber Variable % set noclobber typically contains generic UNIX commands such as the stty, set path, and umask commands. Setting the noclobber variable protects files from being .logout This file, if it exists in your home directory, is automatically accidentally overwritten due to output redirection (but not executed at logout. Must begin with “#” to indicate C shell cp, mv, etc.). “!” following any redirection operator over- script. rides noclobber. .logout Piping Operator % command1 | command2 typically contains commands to perform cleanup.
C Shell Specific Commands Job Control % command & Enable Tracking of % set history=n Running Jobs in the Commands Background % command Displaying Com- % history Stopping Foreground Jobs . mand History . Re-executing Previ- !! previous command . ous Commands !nnth command !string last command beginning with string % !-nnth most recent command Job Status % jobs !?string? last command containing string % kill %job-number % set savehist=n Killing Jobs Saving Command % kill process-id History Bringing Jobs to the % fg %job-number Setting Aliases % alias alias-string command-string Foreground % alias Displaying Aliases Moving Jobs to the % bg %job-number Deleting Aliases % unalias alias-string Background Process Status % ps lists all your processes % ps -a lists all running processes % ps -x full listing for given option Displaying Users % who % whoami