Unix primer: getting started with the Unix and Linux command line

Updated November 2026

Getting started on Unix is easier than it looks. This primer covers the first things you need: logging in, finding your way around, and working with files. Everything here works on Linux, macOS, the BSDs, AIX and Solaris.

Logging in

On a desktop, open a terminal (on most Linux desktops press Ctrl+Alt+T; on macOS open Terminal from Applications › Utilities). To work on a remote server, connect with ssh:

ssh joe@server.example.com

You are asked for a user name and a password. Both are case sensitive: Joe and joe are different users. Nothing appears on screen while you type the password; that is normal.

Once you are in, you see a prompt, often ending in $ for a normal user or # for root. The program that shows the prompt and runs your commands is the shell, usually bash or zsh.

How a command looks

ls -l /etc

The first word is the command (ls, list files). Words starting with - are options that change what it does (-l, long format). The rest are arguments, usually file or directory names (/etc). Separate them with spaces.

Two keys save a lot of typing: Tab completes command and file names, and the ↑ arrow brings back earlier commands.

Directories and paths

Unix files live in one tree that starts at /, the root directory. There are no drive letters. A path is the list of directories to a file, separated by forward slashes.

pwd                 # print working directory: where am I?
cd /tmp             # change to /tmp
cd ..               # go up one level
cd                  # go back to your home directory
cd -                # go back to the previous directory
mkdir projects      # make a directory
mkdir -p a/b/c      # make a whole path at once
rmdir projects      # remove an empty directory

Important directories you will see on most systems:

DirectoryContains
/homeUsers' home directories (/Users on macOS)
/etcSystem configuration files
/usr/bin, /binPrograms
/var/logLog files
/tmpTemporary files, often cleared at reboot
/rootThe administrator's home directory

Working with files

ls                  # list files in the current directory
ls -la              # all files, including hidden ones (names starting with .), in detail
cat notes.txt       # print a short file
less big.log        # page through a long file (q to quit, / to search)
cp notes.txt copy.txt          # copy a file
cp -r projects backup/         # copy a directory and everything in it
mv copy.txt old.txt            # rename a file
mv old.txt archive/            # move it into a directory
rm old.txt                     # remove a file
touch empty.txt                # create an empty file (or update its time)
There is no recycle bin

Unlike deleting on the Windows or macOS desktop, rm does not use a Recycle Bin or Trash: it deletes immediately and you cannot undo it. Double-check before you press Enter, especially with rm -r and wildcards. Use rm -i to be asked about each file.

Wildcards let one command work on many files: * matches anything, ? one character. ls *.txt lists all files ending in .txt; rm draft?.doc removes draft1.doc and draft2.doc.

Editing files

Every Unix system has vi, so it is worth learning the basics (see vi). Beginners usually find nano easier: the commands are listed at the bottom of the screen, and Ctrl+O saves, Ctrl+X quits.

nano notes.txt
vi notes.txt         # i to type, Esc then :wq to save and quit, :q! to quit without saving

Permissions in one minute

$ ls -l report.txt
-rw-r----- 1 joe staff 1204 Nov  2 10:15 report.txt

The first column shows who may read (r), write (w) and execute (x) the file: first the owner (joe), then the group (staff), then everyone else. Here joe can read and write, the staff group can read, and others have no access. Change permissions with chmod: chmod g+w report.txt lets the group write too.

Pipes and redirection

Unix commands do one job well and can be joined together. The | (pipe) sends the output of one command into the next; > writes output to a file.

ls -l | less                    # page through a long listing
grep error app.log | wc -l      # count lines containing "error"
ls /etc > etc-files.txt         # save the output to a file (overwrites)
date >> log.txt                 # append to a file

Getting help

Every command has a manual page. man shows it, and man -k searches the descriptions when you do not know the command's name.

man ls              # the manual for ls (q to quit)
man -k "copy file"  # find commands about copying files
ls --help           # short help on Linux (GNU) commands

Logging out

Type exit or press Ctrl+D. Always log out of shared machines when you leave.

Quick reference

To do thisType
Which directory am I in?pwd
Change directorycd directory
Make a directorymkdir directory
Remove an empty directoryrmdir directory
List filesls -l
Show a fileless file
Copy a filecp file1 file2
Move or rename a filemv file1 file2
Remove a filerm file
Find a filefind . -name "*.txt"
Search inside filesgrep word file
Who am I?whoami
Help on a commandman command

Next steps: browse the command reference, then learn to automate your work with shell scripting.