back

Useful unix commands

Of course, all unix commands are useful. But some are easier to pick up and are more useful than others. This list was originally based upon the list in the SO11 handbook, but has expanded somewhat as I think of stuff. The aim is to be concise but useful.

This page is split into Basics, a really general overview; Account basics and finding out help covering inbuilt help systems and password stuff; Moving around directories and files; Printing; Dealing with disk space including checking your quota and finding large files; Examining text files.

Basics

Unix commands are case sensitive and nearly always in lower case. Most have options that will enable you to alter the way in which they behave - e.g. ls = list files, ls -l = list files and their attributes, ls -a = list all files. To find out the options available, commands have 'man pages' which are manuals you can browse through. These are not always the easiest documents to follow, but you should get the hang of finding things in them if you look around.

Account basics and finding out help

passwd - change your password

man - manual pages: you need to type man then the command you are trying to find the manual for, so man passwd would tell you all about the passwd command. To search through the "man pages" for a command, you can use / followed by a string to search through the document. (The man page viewer uses less, a general text-file viewer - see below for more detailed commands).

info is a rival system to man (urgh) which is used by some Gnu systems - the interface is IMHO much worse.

apropos - search for a word in manual pages. So if you were looking for a command that dealt with email, you could type apropos email and it would tell you all manual pages that featured that word (and by implication all packages that have that word in their manuals).

quota - find out your disk quota and how much you have used

Moving around directories and files

cd - changes directory

ls - lists files

cp - copies files

mv - moves files

rm - removes (deletes!) files

rmdir - removes (deletes!) directories

Printing

printers - show the names of available printers

lpr - send a file to a printer; you will need to name the printer and the file (see man lpr for more details)

a2ps - send any file to a postscript printer (most printers in the SCS are postscript, so this command can be very useful). Again you will need to name the printer and the file, e.g. a2ps -Puglw textfile.txt is the command you would use to send to the undergraduate laser writer (uglw) printer (-P) the file textfile.txt. To find out more, again, look in the man pages.

lpq - look at a printer queue. you'll have to specify the printer name.

lprm - remove a file from a printer queue.

Managing disk space

quota tells you how much quota you have left. quota -s gives you it in human readable form.

ls -lh gives you a directory listing with the long (-l) layout, which has size information, and the -h prints it in human readable form

du tells you your disk usage. du -h gives machine-readable output.

df tells you about the disk filesystems available on your machine. df -h gives human readable output

find has to be one of the most useful unix commands and is worth a page on its own (or perhaps alongside grep), but for disk space issues you want find ./ -size +1M -print which lists all the files above 1 Megabyte.

Looking at text files

cat just spews a file onto the terminal window - so to examine the contents of the file "thingy" type cat thingy

more and less are sophisticated text-file viewers (not editors though) which let you search using "/". To page down within these applications use the space bar, and to page up use "b"

tac is cat backwards - so if you want to look at a file backwards, you can.