This document and its successor summarize the essential commands needed to edit, compile, and run programs in the Linux environment. There are many more detailed tutorials on these topics on the Web; here are a few:
emacs
:
emacs
. After starting
the editor, hit `Control-H' and then `t'.
vi
:
vimtutor
at the shell prompt.
ddd
or gdb
:
There is also a good book available from O'Reilly which covers all of this material in more depth: ``Programming With Gnu Software'', by Mike Loukides and Andy Oram.
The following material was originally written by Art Matheny of the University of South Florida, formerly available at http://curiac.acomp.usf.edu/ism3230/unix.html. It has been modified slightly to match the environment here at DePauw.
This tutorial is for those who have never used Unix before. It covers only the most essential commands that you need to begin with and indicates where to look to learn more. It is assumed that you have this document in printed form so that you can go through the steps on the computer as you read.
To begin with, you need to log in to oort or one of the Linux
machines in Julian 276. If you want to log in from across the network,
use ssh oort.csc.depauw.edu
(on Windows you will need to install a client such as
PuTTY
, available from
http://www.chiark.greenend.org.uk/~sgtatham/putty/). For a graphical
interface, use the X-Win32 program installed on the campus lab PCs.
You will need the username and password from the sheet I gave you (and you will
probably want to change the password to something more memorable, with the
kpasswd
command).
Unix is fundamentally a command-line operating system. If you are logged in with an X Windows session (either in 276 or by using X-Win32), you will see a familiar windowed interface, but this is just a front-end for the underlying system. To do much of your work, you will need to open one or more ``Terminal'' windows.
To make it go, you have to type in commands at what is called ``the unix
prompt''. The prompt is usually the name of the host followed by a
dollar sign, but it varies depending on how the system administrator
has set it up. When the cursor is on the line with this prompt, unix is
awaiting your command. In the examples below, we will assume the
prompt is ``oort$
''. You do not type the prompt; you type what comes
after it.
Here is a walking tour of some essential unix commands:
oort$ ls
oort$ cp /proc/version version
oort$ ls
version
'' among any other files that you have.
oort$ ls -l
-l
'' option specifies that you want a ``long''
listing, which shows lots more information that just the file name.
oort$ cat version
oort$ pwd
Take a close look at the output of the pwd
command. This is what is
called a ``path'' in unix. Unix organizes files in one big tree, where
each node of the tree has a name. The path is the sequence of nodes the
system needs to follow to get from the root of the tree to your home
directory.
oort$ mkdir xyz
mkdir
command makes a new directory. Let's see where unix
put it.
oort$ ls
xyz
directory is within your home directory. Directories can contain
directories as well as files! You can now put files in the xyz
directory.
oort$ cd xyz
xyz
subdirectory.
oort$ pwd
xyz
node has been added to the path.
oort$ cat version
version
in the
current directory.
oort$ emacs tutorial
emacs
and back at the unix prompt.
oort$ ls
ls
command shows the files in the current directory, which is
the xyz
subdirectory. So the files in your home directory do not
appear. The only file that show up at this point is the file that you
just created with the text editor.
oort$ cd ..
oort$ pwd
You should now be back at your home directory. When you said ``cd ..
'',
the current directory moved from xyz
to its parent, which is your
home directory. The xyz
directory is a ``subdirectory'' of your home
directory. The home directory is the ``parent'' of xyz
. A directory may
contain any number of subdirectories, but a directory has one and only
one parent. (Exception: the root directory, whose name is just /
, has no parent.)
oort$ mv version oldversion
oort$ ls
version
is gone, but oldversion
is now there. It is the same
file, but with a different name.
oort$ mv oldversion xyz
mv
because the destination is a
directory.
oort$ cd xyz
oort$ ls
oldversion
has been moved into the xyz
subdirectory.
oort$ cat version
version
in the current directory. But we know that there is a file
named version
somewhere in the tree. How do we access it?
oort$ cat /proc/version
/
) and list all
of the nodes in the path from the root directory to the file. In this
case the path is short, but in general there may be many nodes to type.
oort$ cd
cd
with
no arguments does exactly that.
oort$ ls xyz
xyz
directory.
oort$ cat xyz/oldversion
oldversion
file. This command
illustrates what is called a ``relative path'' name of a file. Since the
path does not begin with a slash (/
), the system follows the specified
tree nodes beginning with the current directory. So the path is relative
to the current directory.
oort$ ls ..
..
'' to access the parent
directory. This command therefore shows what is in the parent of your
home directory (probably a bunch of other people's home directories).
oort$ man ls
man
command takes the name of a command or program as
its argument. It displays the manual page for that command or program.
In this case, you see the man
page for the ls
command.
When you are in the man
display, use the following commands:
space bar | advance to the next page |
return (or enter) | advance one line |
q | quit |
? | help |
Now that you know about the man
command, you can find out about other
important unix commands. What you should do now is read the man
pages in
the list of must-know commands below. These give a lot more detail than
what you need to know to get started, but read the description of what
the command does and skim the rest just to see what information is
available.
man |
Manual page |
more |
Display a file one screen at a time |
ls |
List files in a directory |
cp |
Copy a file |
pwd |
Show path of current directory |
rm |
Remove (delete) a file |
rmdir |
Remove a directory |
mkdir |
Make a new directory |
kpasswd |
Change your login password |
date |
Show the date and time |
emacs |
Text editor (vi is also popular) |
lpr |
Print a file |
talk |
Live communication with other users |
w |
Show who is logged in and what they are doing |
ps |
Show what processes you are running |
wc |
Word count utility |
Part 2 will continue with the use of g++
and make
to build
programs written in C++.