Download as pdf
Download as pdf
You are on page 1of 2

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


% <CTRL-D>
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
<space> next page User and Permission u file owner (u is short for user)
<return> next line Types g group members
o all other users
q quit
r read permission
Copying Files % cp file1 file2
% 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
Removing Files % rm filename 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
Output Redirection % command > filename executed at login. Must begin with “#” to indicate C shell
(overwrite) script.
Output Redirection % command >> filename .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
executed at login. Must begin with “#” to indicate C shell
Error Redirection % command >>& filename
script.
(append)
.login typically contains generic UNIX commands such
Noclobber Variable % set noclobber
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 typically contains commands to perform cleanup.
Piping Operator % command1 | command2

C Shell Specific Commands Job Control


Running Jobs in the % command &
Enable Tracking of % set history=n
Background
Commands
Stopping Foreground % command
Displaying Com- % history
Jobs .
mand History
.
Re-executing Previ- !! previous command .
ous Commands !n nth command <CTRL-Z>
!string last command beginning with string %
!-n nth most recent command
Job Status % jobs
!?string? last command containing string
Killing Jobs % kill %job-number
Saving Command % set savehist=n
% kill process-id
History
Bringing Jobs to the % fg %job-number
Setting Aliases % alias alias-string command-string
Foreground
Displaying Aliases % alias
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

You might also like