This tutorial helps you experiment with some basic unix commands. Work through the given examples and then clean up your experiments before continuing with your lab.
Before you begin, you’ll need to know the answers to the following questions:
Your instructor will have to tell you how to access your account and how to start up the X Windows System and desktop environment. Unlike Microsoft Windows and Macintosh operating systems, there are several variations of X11 and many different desktop environments built on top of X11. Generally these desktop environments work on the same principles as Microsoft Windows and Macintosh OSs, so let your intuition guide you.
Regardless of what GUI you use on your UNIX machine, you can always interact with UNIX directly with a Command-Line Interface (CLI). Eventually, your instructor should tell you how to open a terminal window (a.k.a., an xterm or a console window). It will look something like this:
As pictured in this example, I use a two-line prompt:
A UNIX prompt is highly flexible. Yours is probably very simple. The purpose of the UNIX prompt is to prompt you for a command. If you don’t see a prompt, the terminal window is busy working on something else.
For this lab manual, we will use
as a generic UNIX prompt. You don’t need to type in the UNIX
prompt yourself. That’s the prompt from UNIX; you must enter in
the command that you see after the
UNIX interaction consists of three steps which are repeated until you close the terminal window:
The UNIX environment is case-sensitive, and virtually all UNIX commands use lower-case letters. This will cause you a great deal of frustration if you forget it, so keep this in mind.
In order to use a command-line environment, you must learn those commands that the environment understands. Let’s first see what happens if you type something that the environment does not recognize.
Remember, you don’t enter the unix prompt (“
This is the way that UNIX responds when you give it a command it doesn’t understand.
You will create dozens of files as you go through this lab manual, and it’s best to keep them organized separately from the other work that you do. Just as the documents (i.e., files) in a filing cabinet are often kept in manila folders, we can create a container in which to keep related files, called a directory (or a folder).
After you type in the command, you should get the prompt back. If something goes wrong, then you’ll get an error message. But no message means that something was done successfully.
command is the UNIX command to make
a directory. By placing the word
command, you tell the system that you want to make a (sub-)directory
mkdircommand to make a directory in the
character in these directory names is very important because
you’re creating directories within a directory. This allows you
to keep the files for this course separate from other files you might
gives no feedback unless something goes wrong. So how do we know it
command displays a listing of the
contents of a directory. If all is well, you’ll see at least the
directory. You’ll undoubtedly see other directories and files,
but the specifics differ in each type of UNIX.
But where are those other directories you created? They’re inside
command can also be used to find out what is in a particular
If you follow the
command with the name of a directory, it displays that contents of
that directory. Now you can see the (sub-)directory that you created
To get a more detailed listing of the current directory, enter
-lis called a switch or flag that causes the
lscommand to generate a long (i.e., detailed) listing. The hyphen indicates to
lhas a special meaning; it’s not the name of a directory or file. All UNIX commands have flags like this.
When you begin a computing session, UNIX always starts you out in your home directory. You do not have to remain in your home directory; you can change to a different directory whenever you like.
The directory in which you are working at any particular time is
called your working directory. To find out the name
of the working directory, you can use the
(print working directory)
UNIX systems (like all modern operating systems) utilize what is
called a hierarchical directory system, meaning that
directories can contain other directories. There is one root
directory denoted by
(a single forward slash) which is the top directory; all
other directories are directly or indirectly inside this root
This lists the contents of the root directory. Within
are a number of subdirectories, including
. Each of these contain other directories and files. On many UNIX
systems, the home directories of the users are stored within the
directory. Here is what this might look like on a particular machine:
UNIX treats the tilde character (
) as an abbreviation for your home directory, which can save you a lot
of typing if the path to your home directory has lots of characters.
If you created all of your files in your home directory, it would soon become cluttered. By grouping related files within a directory, you can organize your files.
Since you are working on a lab exercise for this course, let’s change the working directory to the appropriate directory.
command is the change directory
command that changes the working directory to the specified directory.
Similar to the
will not display anything if it works successfully (although you might
notice a change in your prompt). You will see an error message if
command to see if you’re where you think you should be.
command allows you to navigate down a directory hierarchy. What about
going back up the hierarchy?
to list all of the contents of a directory, including files and
directories whose names start with a period (
You will notice two odd items in this output: a period
and a double-period
. In the UNIX file system,
is another name for the working directory (whatever directory you are
is another name for the parent directory of (i.e.,
the directory above) the working directory.
within your home directory. The
command took you from your home directory “down” into
. Once in that directory,
refers to that same directory while
refers to the directory that contains it (i.e., your home directory).
command took you one level lower into the
directory. Now that you’re in the
entry refers to itself, and its
refers to the
So now, to go back “up” a directory, you can enter this command:
is always a synonym for the parent of the working directory,
regardless of any actual names, you can always use this command in any
There’s also a shortcut for changing directories back to your
home directory: use the
command without any arguments:
to verify that you are currently in your home directory.
UNIX stores all data in files. It stores textual data and programs in text files.
You can create a simple text file using a standard editor (e.g., VI, emacs, gedit, etc.) or within a more complex integrated development environment (IDE) (e.g. Eclipse).
computing/practicesub-directory you created above under the name
It is sometimes useful to view the contents of a file (without printing it or loading it into an editor). For example, this can be useful to verify that the files you’ve submitted electronically were submitted properly. When you do need to view the contents of a file, use the following command:
cdinto the directory that contains the file (i.e.,
computing/practice/) and then use the
UNIX provides commands for copying files or directories from one directory to another. The smae command is used for copying a file to a new filename, and for copying the file into a different directory. The general form of the command is:
cp filename targetDirectoryOrName
given is a directory, a copy of the file will be put in the specified
directory. If it is a filename, a copy of the file will be made with
the new name.
catto verify that you now have two files with the same contents.
This copy command will copy a single file to the specified target directory. To move an entire directory and all its descendants, you can use the -r switch:
cp -r directoryname targetdirectory
This command copies the directory file and recursively copies all of its contents.
You can use the
command to remove a directory just
like you’d use
to make a directory.
Whatever directory you specify following the
command will be removed from the file system, provided that the
directory being removed is empty. To remove a non-empty directory
, use this command:
unix-% rm -r directoryName
Be very careful when you use this command. The system will
delete this directory and all its sub-directories without giving you
any feedback, so be sure that
contains nothing important!
rm -rcommand to remove the
computingdirectory. Then, use the
lscommand to verify that the
computingdirectory (and its sub-directories) no longer exist.
Here is a quick reference guide for these basic Linux/UNIX commands.
If you are in the midst of lab01, you should now return to those instructions.