Basic UNIX Commands

Index

In examples of commands these notations are used:

For all the commands in this writeup, use the ``man'' command (q.v.) for an explanation of numerous options not described here.

General UNIX commands:

While "graphical shells" exist for UNIX that imitate the Apple Macintosh or MIcrosoft Windows, most users stick with the traditional command line interface. You type commands one by one on your terminal or into a terminal window, press ``return'', and they are executed. The program which interprets your command is called a ``shell''; q.v. for handy tricks for getting the most out of your shell.

^C
Control-C will usually kill whatever you are doing and signal the shell to accept the next command. Use ^C only if you are stuck, since work you did during the killed command may be lost.
^Z
Usually typed by accident, this control code temporarily suspends a command, whereupon the shell can accept the next command. Use ``fg'' (``foreground'') to get the suspended process running again; type ``jobs'' to see if you have any suspended or background processes. Do not use ^Z unless you really intend to, particularly when editing files or reading mail, since you can easily get inconsistent versions or lose mail if you execute the command a second time without finishing the first one.
logout
Ends your session. Important: you must logout every time you are finished at the terminal or other userss will be able to change your files. On office machines please do not leave idle sessions active overnight, both because of the security hazard and because the unused programs use up system resources.
passwd
Changes your password. You will be asked to type the old password first, and then the new password twice. None of this is visible on the screen. A good password is as long as possible (up to 8 characters, sorry), has a mixed alphabet (some from each of lower case letters, upper case, digits and punctuation), and is not derived in an obvious way from a natural language word (hackers have non-English dictionaries too) or a number or identification code specific to you.
man <command>
Gives information from the UNIX manual about <command>. ``man -k <keyword>'' will list man pages whose titles contain the keyword.
finger <name>
looks up the loginID of <name>, e.g. ``finger Tadeusz'' will give you the loginID (and full name) of everyone named Tadeusz. Be prepared for a lot of output with common names. You can also specify the loginID to find the person's full name.
mail
An obsolete program to read and send mail. We're recommending that people learn ``pine''.

What is a File?

In UNIX data is stored in a ``file''. Each file has a name, which you create. Filenames should be composed of letters (upper and lower case), numbers and simple punctuation; hyphens and underbars are safe. Actually any character can be used except slash, but you have to do extra work to specify non-alphanumeric filenames, and you'll regret using one. Many filenames end with an extension, i.e. a period and one to three letters. It is conventional to use an extension that signifies what is in the file, e.g. ``.c'' for ``C'' language source code or ``.gif'' for an image in the GIF format. Some programs such as web browsers depend on the extension to tell how to process the file.

Files are indexed in ``directories''. Every user has a ``home directory'' and you can (and should) create sub-directories within it, one for each project or purpose. Every process executes ``in'' a particular directory called the ``current directory''. Use the ``cd'' command to change to another directory. Files in the current directory are accessed just by their names. To specify a file in another directory give the name of that directory, slash, the filename. (Recursively, if the directory isn't in the current directory.) The directory that contains a directory can be referred to as ``..'' (dot-dot), and the home directory is abbreviated ``~'' (tilde) or ``$HOME''. Here's a complicated filename: ``~/tasks/lapack/Notes2.txt''. This means: In my home directory, subdirectory ``tasks'', its subdirectory ``lapack'', the file ``Notes2.txt'' (which judging from the extension probably contains text).

See ``Shells'' for how to use pattern matches to name multiple files at once.

Files whose name begins with ``.'' (period) are special; see the ``Dotfiles'' writeup.

Commands Related to Files

quota
Check your quota of file space. If it prints nothing, you're OK. Do ``quota -v'' to see a report even if you're not over quota. Please remove files that you're not going to use any more, particularly large ones.
ls
List of files. You may specify specific files or directories to be listed. ``ls -l'' gives a "long" list showing the file's date, size and permission. ``ls -s'' gives a simple list with sizes in thousand bytes. Files whose names begin with ``.'' (period) normally are not shown; ``ls -a'' shows them.
mkdir <directory>
Make a directory.
cd <directory>
Change to that directory, which becomes the current directory. ``cd ..'' (to the containing directory) is often useful. ``cd'' without arguments changes to $HOME, your home directory.
cp <old> <new>
Copy a file.
mv <old> <new>
Move or rename a file. It could be moved to a different directory and the simple name could be changed. If the ``new'' name is a directory that already exists, the ``old'' file will be placed in it. This form still works if several ``old'' files are specified.
rm <file>
Remove a file. Be careful; you can't un-remove it later. But please remove files you aren't going to use any more. rm -r <directory> will remove every file in the directory, recursively, then remove the directory itself.
chmod <perm> <file>
Set the permission of one or more files or directories. Useful permissions are:
600
Only you can use the file.
700
Same, for directories and executable files.
644
Anyone can look at the file; only you may write. This permission is required if a file is to be visible on the World Wide Web.
755
Anyone may look at files in the directory (if the file permission allows); only you may put files in it.
711
For directories, anyone may use a file if the name is known (or guessed) and the file permission allows, but others may not do ``ls'' in the directory to snoop for other filenames. Often used on home directories.
File etiquette: if the owner set permission 644 then s/he intended you to be able to see the file; don't be shy about looking.
Creating a file
You create a file using an editor, q.v., or by output redirection, for which see ``Shells''.

Miscellaneous Useful Commands

rup <host>
Shows the load on one or more hosts (a specific computer). Without the argument it will show data for all machines on the network segment.
who
Lists all users on the computer in which you are currently working.
who am i
Tells who is currently logged on a specific terminal
date
Prints the current date and time.
hostname
Tells you the name of the computer on which you are currently working.
crypt <input >output
Encrypt or decrypt a file (it knows which way to go). It will ask you for a key (see ``passwd'' above for suggestions). The algorithm is not sufficiently strong for national security issues. The command line shown uses input and output redirection, q.v.
gzip <file>
Compresses the file. The full-size file is removed and the compressed file has the same name with an extension of ``.gz'' added. You can get 4 to 1 compression on low-entropy data.
gunzip <file>
The inverse of gzip: restores the original file.
lpr <file>
Print the file. See ``Printing'' for details. Mind your paper quota. Save a tree; look at documents on the screen.

Special PICnet commands

demo
Short demonstration program introducing the student to the use of the terminal (special keys and functions)
home
Tells you which machine is your home site.
handout
A program which allows the user to read, print and make copies of general handouts.