A Brief Unix Tutorial
Terminal Windows
The UNIX operating system is accessed via a terminal window . A terminal window
can be opened using the icon at the botom of your screen. When the window is opened,
a prompt appears (usually the name of the computer you are using) and you can enter
various UNIX commands to perform various tasks. A few of these tasks are outlined below.
Directories
The UNIX shell keeps track of your "working directory" or "current directory." The current directory is the directory
(or, if you prefer, the folder) where you are currently working. All file- and directory-related commands
will be performed relative to the current directory. For example, ls will list the contents of the
current directory only.
pwd Show the directory you are currently in.
cd destination Change Directories from current directory to destination directory
cd .. Move to the parent of your current directory
cd Move to your home directory
mkdir dirname Make a new directory named dirname
rmdir dirname Remove a directory named dirname. NOTE: All files must first be deleted.
Files
Many of these commands also apply to directories.
ls List the contents of the current directory.
ls -l Give a long-form listing, with lots of information about each file and directory.
ls -a Do a normal ls, but include all files whose names begin with a period (hidden files).
ls -F Do a normal ls, but mark all executable files with a *, and all directories with a /.
ls -laF Do all of the above.
mv oldFileName newFileName Move (or, more precisely, rename) the file oldFileName to the file newFileName.
mv file dirName Move a file into directory named dirName.
cp fileName newfileName Copy the file fileName to the file newFileName.
cp file dirName Copy a file into a directory.
rm file Remove (that is, delete) a file. There's no "undelete" command, so be careful.
cat file "Concatenate" the file--that is, print its entire contents to the screen, all at once.
For big files, you'll want to use more file.
more file Print the file on the screen, one window's worth at a time. While you're using more,
the spacebar will move you forward one screen, b will move you back one screen, the enter
key will move you forward one line, "/something" will move you to the next line that
contains "something," and q will quit.
Command shell commands
The command shell is the program that prints the prompt and executes your commands.
!! Execute the previous command again.
!something Execute the most recent command that began with "something."
<TAB> If you have typed enough of a file name to uniquely identify the file, pressing the
TAB key will complete the file name for you.
* The * represents any string of characters. Thus,
ls b* will list all files whose names start with b (UNIX is case-sensitive with respect to
file names, by the way, so ls b* will not list files whose names start with B).
Similarly, ls *b* will list all files whose names contain b.
Compiling and running Java programs
Use a text editor to create the source file: myprogram.java and save it
in some subdirectory of your home directory. In a terminal window use
cd as explained above to get to this directory. Compile your code
using javac myprogram.java and run it using java myprogram.
Getting documentation
Type man ls to read the documentation describing ls. Same for other commands.
Jack Goldfeather,
Department of Mathematics and Computer Science,
Carleton College, Northfield, MN
55057,
(507) 646-4366
jgoldfea@carleton.edu