Common Unix Commands

Commands

When an argument appears in brackets, it is optional or only required in certain circumstances.

A vertical bar separating two arguments is a logical OR.

Words in ALL_CAPITALS are placeholders.

apropos

Takes the word you give it as an argument and searches the short description line at the top of all man pages for a match.

apropos KEYWORD

bash

Starts a bash shell as a subprocess of your current shell.

bash

bg

Sends a suspended job into the background, where it resumes running.

If there is more than one suspended job, the job number must be given as an argument.

bg [JOB_NUMBER]

cat

Prints the contents of the file given as its argument to the screen.

Options
-n Prints the line number at the beginning of each line
cat FILENAME

cd

Changes your current directory.

When no directory name is specified, your home directory is assumed.

To go up one level to the parent directory, use .. instead of a directory name.

cd [DIRECTORY_PATHNAME]

chmod

Changes permission on a file or directory.

The permissions may be specified, relative to their current state, by a symbolic argument, or absolutely by a numeric argument.

chmod PERMISSIONS FILENAME|DIRECTORY_NAME

cp

Creates a copy of a file or directory.

Options
-r Copies a directory and all its contents
cp FILE_1|FILE_2

date

Prints the current date and time.

date

diff

Prints the difference between two files.

Options
-y Prints the output in human-readable form.
diff FILE_1 FILE_2

echo

Prints the string given as an argument to Standard Output.

Options
-n Does not advance to the next line after printing the string
echo STRING

env

When used without an argument, returns the values of all global variables.

env

fg

Brings the background job specified into the foreground.

Can be used without an argument if there is only one background job running.

fg [JOB_NUMBER]

finger

When run with no argument, displays information on all current users connected to the host.

When run with an argument searches its store of user information to display what it knows about all possible matches to the string supplied.

finger [STRING]

grep

Prints every line in a file where a string occurs.

Options
-i Ignores capitalization when determining a match
-v Returns all lines that do not contain the string
-r Searches recursively through all directories beneath the directory supplied as an argument
grep SEARCH_STRING FILENAME

Prints the first 10 lines in a file.

Options
-NUMBER Returns the first NUMBER lines
head FILENAME

hostname

Returns the name of the host machine.

Options
-i Returns the TCP/IP address of the host machine
hostname

jobs

Returns information on all currently running jobs.

jobs

kill

Stops a background job.

kill PROCESS_ID
kill % JOB_NUMBER

less

Prints the contents of a file one screenful at a time.

less FILENAME

locate

Returns the pathname of every file and directory that contains the search string.

locate SEARCH_STRING

ls

Prints the contents of the directory specified or the current directory if run without an argument

Options
-a Prints all contents of the directory, including the"invisible" files whose simple names start with a .
-l Prints a long listing of the directory contents showing the owner, group and permissions of each entry
-d Prints a directory rather than its contents
-t Sorts the list by modification date rather than alphabetically
-r Reverses the sort order of the list
ls [DIRECTORY]

ln

Creates a link to a file or directory.

Usually run with the -s option to create a symbolic, rather than a hard link.

Soft links are more flexible than hard links.

If no second argument is used, the name of the link will be the same as the file or directory pointed to by the link.

ln -s PATHNAME [LINK_NAME]

man

Prints information on the command given as its argument.

man COMMAND_NAME

mkdir

Creates a directory with the name specified.

mkdir DIRECTORY_NAME

more

Prints the contents of a file, one screenfull at a time

more FILENAME

mv

Moves a file from one place to another, when the second argument is a directory.

Also used to rename a file.

mv FILENAME DIRECTORY_NAME
mv OLD_FILENAME NEW_FILENAME

pwd

Prints the absolute pathname of your current directory.

Options
-P Prints the "true" absolute pathname of the current directory, that is, it does not use a link in the pathname it returns, even if you used that link to get to the current directory
pwd

rm

Deletes a file.

Cannot be undone.

rm * removes everything in the current directory.

Will not remove a directory unless used with -r option.

Options
-r Remove directories and their contents recursively
-i Prints a prompt before removing a file or directory
-f Force - ignores warnings
rm FILENAME

rmdir

Removes a directory.

Command will not work if the directory is not empty.

rmdir DIRECTORY_NAME

script

Creates a record of your Unix session.

Once you run script everything you type and all output from the screen is recorded in a file, whose name by default is typescript.

Options
-a Appends output to a previously created typescript file
script

sort

Prints a file with each line sorted alphabetically.

Options
-r Reverses the normal sort order
-n Sort in numeric, rather than alphabetical, order
sort FILENAME

ssh

Allows you to login to another Unix machine from your current Unix machine.

    
ssh UNIX_ACCOUNT_NAME@HOST_NAME

tail

Prints the last 10 lines in a file.

Options
-NUMBER Returns the last NUMBER lines
tail FILENAME

tee

When placed in a pipeline, sends its output to a file before passing it to Standard Output.

tee FILENAME

uname

Prints some system information.

Options
-a Prints more complete information on the current system
uname

uniq

Prints a file with adjacent identical lines removed.

uniq FILENAME

which

Prints the absolute address of the executable file for a given Unix command.

which COMMAND_NAME

who

Shows all currently logged in users.

who
Copyright : Glenn Hoffman, Director of the IT program, Umass-Boston