UNIX Programming, Certification, System Administration, Performance Tuning Reference Books
UNIX Commands Cheat Sheet
Commands
Note: Most but not all of the commands listed herein are part of UNIX, some may not be available on every UNIX system. These commands are available on rci and eden. Where the behavior is different between eden and rci it will be noted.
NOTE: Items in italics indicate either a place holder where you would place specific information or and item that may be omitted.
Command Description Usage
On-line Help
man
display reference manual pages
man cmd_name
Basic Options:


-k locates commands by keyword lookup
-s specifies a chapter or section to look in
-u basic usage description


man -k keyword
man -schap# cmd_name
man -u
whereis
locate the executable, source, and man page files
whereis command
Basic Option:


-h basic usage description

whereis -h
Communicating With Other Users
chfn
change finger entry 
chfn
finger
lists information about users
finger username
Basic Option:


-h basic usage description

finger -h
from
see who your mail is from
from
Basic Option:


-h basic usage description

from -h
ftp
file transfer protocol


Transfers files from one networked computer where you have an account to another where you have an account.

ftp computer.domain
mail
not supported
mail
mesg
permit or deny messages from write and talk
mesg y or mesg n
pine
mail program recommended by RUCS
pine
Basic Option:


-h basic usage description

pine -h
talk
"talk" to another currently logged in user
talk username
telnet
login on another computer on the network
telnet computer
w
list who is on the system and what they are doing
w
who
list who is on the system
who
whodo
list who is on the system and what they are doing
whodo
write
send an interactive message to another user
write username
zmail
mail program, not supported, may be removed soon
zmail
Basic Options:


-gui starts with Graphic User Interface, works only on X terminals
-h basic usage description


zmail -gui
zmail -h
zmlite
mail program, not supported, may be removed soon
zmlite
Basic Option:


-h basic usage description

zmlite -h
Dealing with the File System
cat
concatenate and display arguments to standard output
cat file
cd
change directory


Note: given a full or relative path, set the working directory as specified; without arguments set the working directory to the login directory

cd path
Basic Option:


-h basic usage description

cd -h
chmod
set the protections on a file
chmod code file
In the numeric mode the three numbers represent the protections for the user, group and others. Each number is a sum of 1 (for execute access), 2 (for write/delete access) and 4 (for read access). "chmod 750 file.name" sets full access for the user, read and execute for the group and no access for others
chmod ### file
In the symbolic mode the options first indicate whose access is to be changed u (user, you), g (group), o (other), or a (all); then indicate the type of action + (add), - (delete), or = (set); and then specify the access to be set r (read), w (write/delete), or x (execute). &qiot;chmod o-rwx file.name" denies others from having any access to file.name and has no affect on user/group access
chmod ugoa+-=rwx file
Basic Option:


-R descend into subdirectories

chmod -R code file
cp
copy files
cp fromfile tofile
Basic Option:


--help basic usage description

cp --help
diff
compares two files and reports the differences
diff file1 file2
Basic Option:


--help basic usage description

diff --help
du
display disk usage


NOTE: On rci 'du' and 'du -k' both yield results in 1 kilobyte blocks, while on eden 'du' yields results in ½ kilobyte blocks and 'du -k' yields results in 1 kilobyte blocks.

du
Basic Options:


-k show usage in 1 kilobyte blocks
--help basic usage description

du -k


du ---help

file
determine the type of a file
file filename
Basic Option:


-h basic usage description

file -h
ftp
file transfer protocol


Transfers files from one networked computer where you have an account to another where you have an account.

ftp computer.domain
grep
search for a character string in a file
grep string file
Basic Options:


-v show lines that do not contain the string
-h basic usage description

grep -v string file


grep -h

gzip
compress a file to take up less space
gzip filename
Basic Option:


-h basic usage description

gzip -h
gunzip
re-expand compressed files
gunzip filename
Basic Option:


-h basic usage description

gunzip -h
head
Show the first 10 lines of a file
head filename
Basic Options:


-# show first # lines of the specified file
--help basic usage description

head -20 filename


head --help

ispell
check the spelling of the contents of a file
ispell file
Basic Option:


-h basic usage description

ispell -h
less
browse or page through a text file.


Usage: press the space bar to go forward a page, type b to go back a page and type q to quit.

less file
Basic Option:


-h basic usage description

less -h
lpq
check the status of a print queue
lpq
Basic Option:


-Pprinter specifies the printer to be checked

lpq -Pprinter_name
lpr
send a job to a print queue
lpr options file(s)
Basic Options:


-Pprinter specifies the printer
-Bbin specifies the bin
-Nnote print note on burster page
-m send mail upon completion

lprm
remove a print job from a print queue
lprm print_job_#
ls
list the contents of a directory
ls options files(s)
Basic Options:


-a all files
-d list directories not their contents
-F mark directories with /, executable files with *, symbolic links with @, and sockets with =
-l long listing showing protections, number of links, owner, size, and time of last modification
-s size in kilobytes
--help basic usage description

mkdir
create a new subdirectory in the current directory
mkdir subdir
create a new subdirectory, in the indicated target directory
mkdir subdir targetdir
Basic Option:


--help basic usage description

mkdir --help
more
browse or page through a text file.


Usage: press the space bar to go forward a page, type b to go back a page and type q to quit.

more file
Basic Option:


-h basic usage description

more -h
mv
move or rename files
mv fromfile tofile
Basic Option:


--help basic usage description

mv --help
pr
prepare text for printing with headers and page breaks
pr file
Basic Options:


-h "header text" set the page header
--help basic usage description

pr -h "header text" file


pr --help

lpc
Work with the available printer queues
lpc status all
pwd
display the current directory's full pathname
pwd
quota
check to see if over allowed usage, no response if not
quota
Basic Option:


-v verbose, show status even if not over quota
With this option eden will display more information than rci.


quota -v
rm
remove (delete) files
rm file
Basic Options:


-i interactive, ask before removal
-r recursive, descend into subdirectories removing files and then containing directories.
--help basic usage description


rm -i file
rm -r directory
rm --help
Note: Once a file is deleted, you can't undelete it. Use the -i option to have UNIX ask if you are sure about removing the file.
rmdir
remove empty directories
rmdir dirname
Basic Option:


--help basic usage description

rmdir --help
sort
sort input
sort filename
Basic Option:


-n sort numerically.

sort -n filename
tail
show last 10 lines of a file
tail filename
Basic Options:


-# show last # lines of the specified file
--help basic usage description

tail -20 filename


tail --help

touch
update the time stamp on existing files, create new empty files
touch file
Basic Option:


--help basic usage description

touch --help
umask
display or set the accesses to be denied on newly created files


Each # indicates which accesses (if any) are to be denied to a class of user. The first affects the user (you), the second affects the group, and the third affects all others. If a # is 0 then no access is denied that class of user, 1 denies execute access, 2 denies write access, 4 denies read access, 3 is the sum of 1 and 2 (no execute or write access), 5 is the sum of 4 and 1 (no execute or read access), etc. umask 077 would allow full access by the user and deny all others any access. Usually this command is placed in the file .login to be executed every time you log in.

umask ###
If used alone, display current value, leading zeros not shown
umask
wc
display the number of lines, words and characters in a file
wc filename
Basic Option:


--help basic usage description

wc --help
Work Environment
alias
create a new name for a command or series of commands
alias newname oldname
chsh
change login shell 
chsh
clear
clear the terminal screen
clear
echo
display indicated text or variable contents
echo text


echo $varname

exit
log off the system
exit
id
display your system ID numbers


if given a username, display their ID numbers

id


id username

logout
log off the system
logout
passwd
change the login password 
passwd
printenv
show your current environment variable settings


if given an environment variable name display that setting

printenv


printenv varname

script
make a copy of everything displayed on the screen


Useful for capturing error messages and program execution
Usage: to end scripting, type a <CTRL>d

script filename
Options:


-a append to file rather than overwrite
-h basic usage description

script -a filename


script -h

setenv
set environment variables
setenv varname value
unalias
unset an alias that was previously set
unalias aliasname
unsetenv
unset environment variables
unsetenv varname
reset
reset the terminal screen
reset
whoami
display the current username
whoami
Basic Option:


-h basic usage description

whoami -h
Controlling your jobs
bg
run the indicated job in the background
bg %job#
fg
move a job from the background to the foreground
fg %job#
jobs
list current jobs and their status
jobs
Basic Option:


-h basic usage description

jobs -h
kill
terminate a process
kill %job#


kill process#

nohup
run a command immune to hang-ups


Notes: Standard input, output, and error must be redirected or will be lost. Over use or frivolous use of this can be considered abuse of the system.

nohup command
ps
list current processes
ps
News Programs
msg
use nn to read the system announcements newsgroup
msg
nn
news reading program


if given a newsgroup name, read only that newsgroup

nn 


nn newsgroupname

nnpost
news posting utility
nnpost
Emacs Text Editor
emacs
the emacs editor
emacs filename
teach-emacs
the emacs on-line tutorial
teach-emacs
Languages
adb
general purpose program debugger
adb objectcode
cc
C compiler: 
cc file.c
Basic Option:


-flags basic usage description

cc -flags
CC
C++ compiler: 
CC file.c
Basic Option:


-flags basic usage description

CC -flags
dbx
program debugger
dbx executable
f77
FORTRAN 77 compiler:
f77 file.f
Basic Option:


-flags basic usage description

f77 -flags
f90
FORTRAN 90 compiler: 
f90 file.f90
Basic Option:


-flags basic usage description

f90 -flags
gcc
Gnu C compiler: 
gcc file.c
g++
Gnu C++ compiler: 
g++ file.c
lint
attempts to detect features of C programs that are likely to be errors, non-portable, or wasteful
lint file.c
Basic Option:


-flags basic usage description

lint -flags
make
facilitates compilation of several program modules
make
Basic Option:


-h basic usage description

make -h
pc
Pascal compiler:
pc file.p
Basic Option:


-flags basic usage description

pc -flags
Web Browsers
lynx
text only web browser, usable in telnet sessions
lynx
Basic Option:


-h basic usage description

lynx -h
netscape
graphic web browser, usable on X terminals
netscape &
Basic Option:


-h basic usage description

netscape -h
Miscellaneous Information
cal
display the calendar of the current month


if given a complete year number (02 = 2, not 2002), display that year
if given a month and year number (01 = January), display that specific month

cal


cal yr#
cal mo# yr#

date
show the current system date and time
date
dict
electronic dictionary, thesaurus, familiar quotations, and CIA world factbook
dict
Options:


-d dictionary, default action
-t thesaurus
-q familiar quotations
-w CIA world factbook 

dict -d


dict -t
dict -q
dict -w

units
converts units in one scale to another
units
Basic Option:


-h basic usage description

units -h

Metacharacters

Metacharacters are a group of characters that have special meanings to the UNIX operating system. Metacharacters can make many tasks easier by allowing you to redirect information from one command to another or to a file, string multiple commands together on one line, or have other effects on the commands they are issued in. The following table lists some of the metacharacters for the Rutgers default shell (the T shell).

 

Metacharacter Description
*
A wild card character that matches any group of characters of any length, allowing a user to specify a large group of items with a short string. For example, to specify all the files that start with 'abc', you use abc*.
?
A wild card character that matches any single character. Thus ls ??? lists files in the current directory whose names are only three characters long, while ls ???.* lists those files with a three letter main name and any extension.
[..]
A set of characters that can be matched. Thus ls [a-c]*.??? lists all files that begin with a, b, or c and have a three letter extension and lpr [ad]* prints all files that begin with a or d.
$
Indicates that the following text is the name of a shell (environment) variable whose value is to be used.
|
Separates commands to form a pipe (see redirection in "Intermediate Use Of The UNIX Operating System").
<
Redirect the standard input (see redirection in "Intermediate Use Of The UNIX Operating System").
>
Redirect the standard output (see redirection in "Intermediate Use Of The UNIX Operating System") replace current contents.
>>
Redirect the standard output (see redirection in "Intermediate Use Of The UNIX Operating System") appends to current contents.
>&
Redirect the standard output and standard error (see redirection in "Intermediate Use Of The UNIX Operating System") replace current contents.
>>&
Redirect the standard output an standard error (see redirection in "Intermediate Use Of The UNIX Operating System") appends to current contents.
%
Introduces a job name (see multitasking in "Intermediate Use Of The UNIX Operating System").
&
Place a process into the background (see multitasking in "Intermediate Use Of The UNIX Operating System").
()
Encloses a sequence of commands or pipes to be executed as a single command.
!
Precedes a history substitution (see "man history")
;
Separates sequences of commands (or pipes) that are on one line.
&&
Separates two sequences of commands or pipes the second of which is executed only if the first succeeds.
||
Separates two sequences of commands or pipes the second of which is executed only if the first fails.
\
Used to "quote" the following metacharacter so it it treated as a plain character, as in \*.

Command Line Editing

In the default Rutgers UNIX shell (the T shell) with the default editor set to emacs, commands may be edited and previous commands retrieved using control characters:

 
<CTRL>a move the cursor to the beginning of the line
<CTRL>b move the cursor to the left
<CTRL>c abort the current command
<CTRL>d if not at end of the command line, delete the character at the cursor
if at end of command line, list possible command (or file) name completions
<CTRL>e move the cursor to the end of the line
<CTRL>f move the cursor to the right
<CTRL>h delete the character to the left of the cursor
<CTRL>k erase from the cursor to the end of the line
<CTRL>l clear the screen and display current line
<CTRL>n bring up next command line
<CTRL>p bring up previous command line
<CTRL>q continue displaying to the screen (see <CTRL>s)
<CTRL>r redisplay the current line
<CTRL>s stop displaying to the screen (see <CTRL>q)
<CTRL>t exchange the character to the left of the cursor with the character at the cursor
<CTRL>u erase the current line
<CTRL>w will erase from the cursor to the beginning of the line
<CTRL>y yank back the last item erased by <CTRL>k, <CTRL>u, or <CTRL>w
<ESC> b move the cursor to the left one "word"
<ESC> f move the cursor to the right one "word"
<ESC> c move the cursor to the right one "word", capitalizing while moving
<ESC> l move the cursor to the right one "word", making lower case while moving
<ESC> u move the cursor to the right one "word", making upper case while moving

Return to : Unix System Administration Hints and Tips