Basic UNIX Commands, Metacharacters,
& Command Line Editing
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
man -k keyword
in man -schap# cmd_name
-u basic usage description man -u
whereis locate the executable, source, and man whereis command
page files
Basic Option:
-h basic usage description whereis -h
Communicating With Other Users
chfn change finger entry (disabled on eden and chfn
rci. See note 1 at bottom.)
finger lists information about users finger NetID/username
Basic Option:
-h basic usage description finger -h
from see who your mail is from from
Basic Option: from -h
-h basic usage description
ftp file transfer protocol ftp computer.domain
Transfers files from one networked
Command Description Usage
computer where you have an account to
another where you have an account.
mailx UNIX mail program, not supported. mailx
Usable in shell scripts
pine mail program recommended by NBCS pine
Basic Option: pine -h
-h basic usage description
ssh login on another computer on the network ssh computer
w list who is on the system and what they w
are doing
who list who is on the system who
whodo list who is on the system and what they whodo
are doing
Dealing with the File System
cat concatenate and display arguments to cat file
standard output
cd change directory cd path
Note: given a full or relative path, set the
working directory as specified; without
arguments set the working directory to
the login directory
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 chmod ### file
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
In the symbolic mode the options first chmod ugoa+-=rwx file
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
Command Description Usage
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
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 diff file1 file2
differences
Basic Option:
--help basic usage description diff --help
du display disk usage du
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.
Basic Options:
-k show usage in 1 kilobyte blocks du -k
--help basic usage description du ---help
file determine the type of a file file filename
Basic Option:
-h basic usage description file -h
ftp file transfer protocol ftp computer.domain
Transfers files from one networked
computer where you have an account to
another where you have an account.
grep search for a character string in a file grep string file
Basic Options:
-v show lines that do not contain the
string grep -v string file
-h basic usage description grep -h
gzip compress a file to take up less space gzip filename
Basic Option: gzip -h
Command Description Usage
-h basic usage description
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 head -20 filename
--help basic usage description 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. less file
Usage: press the space bar to go
forward a page, type b to go back a page
and type q to quit.
Basic Option:
-h basic usage description less -h
ln create a link between source and ln source dest
destination files
Basic Option:
-s create a symbolic link ln -s source dest
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
-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
Command Description Usage
-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 mkdir subdir
directory
create a new subdirectory, in the mkdir subdir targetdir
indicated target directory
Basic Option:
--help basic usage description mkdir --help
more browse or page through a text file. more file
Usage: press the space bar to go
forward a page, type b to go back a page
and type q to quit.
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 pr file
page breaks
Basic Options: pr -h "header text"
-h "header text" set the page header file
--help basic usage description pr --help
printers Display the available printers printers
pwd display the current directory's full pwd
pathname
quota check to see if over allowed usage, no quota
response if not
Basic Option:
-v verbose, show status even if not over quota -v
quota
With this option eden will display more
information than rci.
Command Description Usage
rm remove (delete) files rm file
Basic Options:
-i interactive, ask before removal rm -i file
rm -r directory
-r recursive, descend into subdirectories
rm --help
removing files and then containing
directories.
--help basic usage description
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 tail -20 filename
--help basic usage description tail --help
touch update the time stamp on existing files, touch file
create new empty files
Basic Option:
--help basic usage description touch --help
umask display or set the accesses to be denied on umask ###
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
Command Description Usage
file .login to be executed every time you
log in.
If used alone, display current value, umask
leading zeros not shown
wc display the number of lines, words and wc filename
characters in a file
Basic Option:
--help basic usage description wc --help
Work Environment
alias create a new name for a command or alias newname oldname
series of commands
chsh change login shell (disabled on eden and chsh
rci. See note 1 at bottom.)
clear clear the terminal screen clear
echo display indicated text or variable contents echo text
echo $varname
exit log off the system exit
getent print information from a login database getent passwd or group
(passwd or group) getent passwd |
Typically output piped to grep to sort for grep IID#
getent group | wc -l
specifics getent passwd NetID
May also be piped to wc to check the # of getent group groupname
lines
If a NetID is given, that exact NetID is
searched for
If a groupname is given, that exact
groupname is searched for
id display your system ID numbers id
id username
if given a NetID/username, display their
ID numbers
logout log off the system logout
passwd change the login password (disabled on passwd
eden and rci. See note 1 at bottom)
printenv show your current environment variable printenv
settings printenv varname
if given an environment variable name
display that setting
Command Description Usage
script make a copy of everything displayed on script filename
the screen
Useful for capturing error messages and
program execution
Usage: to end scripting, type a <CTRL>d
Options:
-a append to file rather than overwrite script -a filename
-h basic usage description 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 NetID/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 fg %job#
foreground
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 nohup command
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.
ps list current processes ps
Text Editors
emacs the emacs editor emacs filename
pico the pico editor (less powerful than emacs) pico filename
teach-emacs the emacs on-line tutorial teach-emacs
Command Description Usage
vi the vi editor (UNIX default, not vi filename
supported)
Languages
adb general purpose program debugger adb objectcode
cc C compiler: (see note 2 at bottom) cc file.c
Basic Option:
-flags basic usage description cc -flags
CC C++ compiler: (see note 2 at bottom) CC file.c
Basic Option:
-flags basic usage description CC -flags
dbx program debugger dbx executable
f77 FORTRAN 77 compiler: (see note 2 at f77 file.f
bottom)
Basic Option:
-flags basic usage description f77 -flags
f90 FORTRAN 90 compiler: (see note 2 at f90 file.f90
bottom)
Basic Option:
-flags basic usage description f90 -flags
gcc Gnu C compiler: (see note 2 at bottom) gcc file.c
g++ Gnu C++ compiler: (see note 2 at bottom) g++ file.c
lint attempts to detect features of C programs lint file.c
that are likely to be errors, non-portable,
or wasteful
Basic Option:
-flags basic usage description lint -flags
make facilitates compilation of several program make
modules
Basic Option:
-h basic usage description make -h
pc Pascal compiler: (see note 2 at bottom) pc file.p
Basic Option:
-flags basic usage description pc -flags
Command Description Usage
Web Browsers
lynx text only web browser, usable in ssh lynx
sessions
Basic Option:
-h basic usage description lynx -h
netscape graphic web browser, usable on X netscape &
terminals
Basic Option:
-h basic usage description netscape -h
Miscellaneous Information
cal display the calendar of the current month cal
cal yr#
if given a complete year number (03 = 3,
cal mo# yr#
not 2003), display that year
if given a month and year number (01 =
January), display that specific month
date show the current system date and time date
dict electronic dictionary, thesaurus, familiar dict
quotations, and CIA world factbook
Options:
-d dictionary, default action
dict -d
-t thesaurus
dict -t
-q familiar quotations dict -q
-w CIA world factbook dict -w
host Display Computer Hostname & IP
host IP-Address#
information
host hostname
If given an IP address, will attempt to
resolve to a hostname.
If given a hostname, will attempt to
resolve to an IP address.
units converts units in one scale to another units
Basic Option:
-h basic usage description units -h
Note 2:
In order to use the math libraries of linkable subroutines, the last item on the compile
command must be " -lm", as in "cc -o demo demo.c -lm"
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
UNIX interprets a space as a separator not as a character.
* 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") to replace current contents.
>> Redirect the standard output (see redirection in "Intermediate Use Of
The UNIX Operating System") to append to current contents.
>& Redirect the standard output and standard error (see redirection in
"Intermediate Use Of The UNIX Operating System") to replace current
contents.
>>& Redirect the standard output an standard error (see redirection in
"Intermediate Use Of The UNIX Operating System") to append to
current contents.
% Introduces a job name (see multitasking in "Intermediate Use Of The
UNIX Operating System").
Metacharacter Description
& 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 is 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