Unix Cheat Sheet

Created by: David Arnold
Updated: May 2, 2022

Unix Commands

This section of the course describes Unix commands for working with files. One of the innovative concepts in Unix is that everything is treated as a file: text documents and programs that you create are files, executable commands are files, directories are files, even tape drives and terminals attached to the system are files. Obviously directories and tape drives are special kinds of files, but when you are exploring the system, you'll find these special files listed in the same manner that your text files are listed.

When executing a command, Unix examines all the directories in your path trying to find the command. Most commands you will issue will be in one of a few standard directories, all included in your default path. If you enter a command that you think should work and receive the response "Command not found", it could mean that either you mistyped the command, the command doesn't exist on the system, or it is just not in your path. We'll touch a little later on modifying your path.

File Commands

CommandDescriptionSyntax & example
ls Lists the names of the files & directories. It has several options for getting more information. ls   [ filename ]
ls -l (long listing)
ls -a (include hidden file)
ls -F (note directories with "/")
ls -alF (combining options)

cat

Displays the contents of a file to your screen. cat   file-name
less Displays the contents of a file to your screen, one screen at a time. less   file-name
cat   file-name | less
head Displays the first ten lines of a file. head   file-name

You can give the head command a number option if you want to see more or less than the first ten lines of your file.

Usage: head   file-name
            head -20   file-name

tail Displays the last ten lines of a file. tail   file-name
tail -15   file-name
rm Deletes files rm   file-name
rm -i   file-name
mv Move or change name of a file mv   old-file-name   new-file-name
mv   file-name   new-directory
mv   file-name   new-directory/new-file-name
cp Makes a copy of a file cp   original-file-name   new-file-name
cp   original-file-name   target-directory

Directory Commands

This section explains some of the commands used to create and manipulate directories.

CommandDescriptionSyntax & example
cd Change to a different directory cd   directory-pathname
mkdir Create a new directory mkdir   new-directory-name
rmdir Delete (remove) empty directory rmdir   directory
cp -r Copy directory structures (recursive) cp -r original-directory   target-directory
pwd Print working directory; path name of the current directory. pwd

List of Unix Special Characters

Here is a list of special characters or words (strings of characters) which have meaning in most environments:

Special CharPronunciationExplanation
! Exclamation point (bang) Start of a new command
& Ampersand Background the process
&& Double ampersand Logical AND
| Vertical bar (pipe) Redirects output
|| Double vertical bar Logical OR
; SemicolonEquivalent to Return/Enter
< Less thanRedirect input from
<< Double less thanReads from shell input (until [word])
> Greater thanRedirect output to (overwrites)
>> Double greater thanRedirect output to (appends)
>& Greater than ampersandRedirect output and error output to
( Left parenthesisUsed for grouping
) Right parenthesisUsed for grouping

Getting Help & Information

There are three commands that can give you help with and more information about the Unix environment:

Back to top

Logging Off

When finished in the Unix environment, make sure you log off. The commands to log off the system are:

    logout, or
    exit, or
    bye (an alias for 'logout')