From ProgSoc Wiki

Revision as of 06:25, 30 April 2013 by 3trk (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


The Down and Dirty Do It Yourself Guide to UNIX (and UNIX-like Operating Systems)

A delectable author stew consisting of
Matthew Beauregard, Christopher "Aubergine" Fraser
Christian Kent, Gabriela Marcionetti and Jim Wind-driedsocks
Bon appetit!

We find that the best way to get acquainted with a "new" operating system is to get "down and dirty" with it and just try things out. The UNIX operating system is no exception. UNIX -- or at least Linux, a UNIX-like derivative -- is ProgSoc's operating system of choice and is still used considerably, not only in many subjects at UTS but also in the big, bad world outside of uni, so it would definitely be worth your while to attain some level of mastery of UNIX.

We've compiled for you an introductory UNIX tutorial, followed by a few self-contained sections of useful UNIX stuff, to help you get your feet wet and to get you started on the path to computing enlightenment.

As long as you have access to a variant of UNIX that is POSIX-compliant (this includes most System V, BSD and Linux-based operating systems) and a terminal screen or window[1] you should have little-to-no trouble following along (the same could be said for pretty much all of the other UNIX-related chapters in TFM).

A disclaimer: This chapter will not turn you into a UNIX guru. You may not want to be a UNIX guru. You may feel there are better things to do with your life. You may regret choosing to do Information Technology and in six weeks you may run away to become a cage dancer at a seedy strip joint on Kings Cross. This may be a Good Thing. This chapter may create more questions than it answers. This chapter may not answer any of your questions, but that's okay. You can pass some programming subjects without writing a working program, doing any labs or anything else (thank God!). We did.

Basic Concepts

Let's start by taking a look at some basic UNIX concepts and commands you will need to survive in the wilderness of the file system. To extend the metaphor, we will give you a nice big bag of tricks and the only instruction you will receive is how to use the penknife[2]. You won't been told about the jetpack or the 200-room hotel with motor court, but they're down there somewhere in the bottom of the bag and you will have to find them yourself (with the occasional help of a grizzled veteran).

Everything Is A File In UNIX

The three basic things you need to think about when using UNIX are files, directories and accounts.

To UNIX everything on the system is a file, including programs, text documents and hardware devices (Yes, Margaret, even monitors and hard-disks look like files to UNIX). Why is this? Because a file is something you can write to and read from and nothing else, and as you will find out as you do your course that is all you can do to computery things. This is such a fundamental concept of UNIX, that we think it bears repeating:

  Everything Is A File In UNIX 

Remember this, and remember it well! On the system there are tens of thousands of files, some huge, some tiny, some medium sized. With so many files it would be difficult to wade through all of them to find the one you are looking for, so UNIX has a special kind of file called a directory.


Directories are special files which can contain other files, including other directories. This allows you to group files together under logical categories; like all your C programs can go in one directory and all your Java programs can go in another directory. The ability of directories to contain other directories allows you to build up a hierarchy of directories, reflecting the structure of your work. You could stick your C directory and your Java inside another directory called Programming, for example. Later in the tutorial you will be introduced to commands to create and destroy directories.

Your Account and Home Directory

Your ProgSoc account is a directory in which you can store your work and any other little tidbits you may take a shining to while you are using the system. Just as all files have a name, so does your account (also called your home directory). The name of your home directory is the same as the name you use to login with and as an example of a hierarchical directory structure your home directory is contained in the directory progsoc-users along with all the other member directories. The directory progsoc-users is itself contained in the directory home which is contained in the root directory whose symbol is the slash / The root directory is the top of the file system. All files and directories on the system exist somewhere underneath the root directory.

UNIX File System Hierarchy

A few words should be said about the manner in which most variants of UNIX organise files into directories before we continue. Over the years, a standard has emerged, meaning that you should have a pretty good idea as to where various user and system files are located, no matter which flavour of UNIX you are using. Here's a quick overview of some of the standard directories you will encounter, and their purpose.

  • bin where executable (or binary) files i.e. the programs themselves are stored.
  • lib where support (or library) files for the programs are stored.
  • dev a file representation of your computer system's hardware components (or devices -- remember "everything is a file"). You will find this method of hardware representation to be quite convenient and powerful, especially when using pipes (see the section on pipes, below).
  • etc where configuration (or etcetera) files for programs are stored.
  • var where files logging the activity of programs, e-mail, etc. are stored.
  • home as mentioned previously, where users' personal files are stored.
  • tmp a place for programs to temporarily store files they might generate during execution. It is good programming practice to make use of this folder in your programs.
  • usr where applications programs i.e. those programs whose operation do not directly relate

to the functioning of the operating system, are stored.

The Prompt

Before we start you using commands you will need to know a little about the general theory of commands. When you login and go to execute your commands you are faced with the prompt, which is the shell's way of telling you that it is waiting for you to execute some command. The prompt tells you three bits of information:

jimmy@niflheim:~$ _

The first bit before the @ is your username[3]. The second bit (after the @) is the machine you are logged onto (niflheim is but one machine on the ProgSoc network -- for more information on the network, see Apropos ProgSoc). The next thing you see is the directory you are currently in. In the above example the directory name appears as a tilde ( ~ ), which is an abbreviation for your home directory. Finally, the $ _ is where you type your commands to get things done.

Commands are what you type at the prompt for your shell to execute. Whenever you type a command, as you will be asked to do below, always type ENTER at the end. If you don't hit ENTER the shell will not know that you want the command executed and you will spend the rest of your life staring at the screen. So when nothing seems to be happening, hit ENTER.

Navigating the Directory Tree

The two commands useful in moving around the directory tree are pwd and cd. pwd stands for present working directory, which is your current location in the directory tree and cd is an abbreviation for change directory which you use to move from directory to directory. At the prompt on your screen try the command pwd. Just type those three letters in and then press ENTER. As output from this command you should get something like:


If you ever see something like this:

Command not found.

it means that you mistyped the command and you should try again. Whenever you type a command and your shell searches around to find a command with that name. If you spell a command incorrectly the shell will not be able to find that command and you will get back the above error message. It is possible that your misspelling will actually be another command, so be a little careful.

Changing Directories

The cd command is used in two ways: relative and absolute. You can move up and down one level at a time in the directory tree, or if you know the full path to the directory you want you can jump straight to that directory. A path is just the list of directories tracing the path from the root directory to the directory itself. The command pwd returns the path to the directory you're in.

Now for some examples you can try (watch what happens to your prompt):

cd ..
cd ..
cd ..

cd home
cd progsoc-users
cd /
cd /home/progsoc-users/jimmy

cd .. will always move you up one level of the directory tree. Once you reach / you cannot go up any further. If you know the name of a directory in your current directory you can move down into it by typing cd followed by the directories name. That is what we did with cd home and cd progsoc-users. The next two commands are examples of absolute movement. First we moved into the root directory and from there we jumped to /home/progsoc-users/jimmy. The final command, cd is quite important. It is the ruby slippers of the UNIX file system; wherever you are you can get back to your home directory by saying "There's no place like home" three times, typing cd and then pressing ENTER. Remember this.

Looking in Directories

In this section we are going to play with the command ls, which is used to display information about files and directories. Try using ls. cd to your home directory, then type:

ls -a

and you might get something that resembles this:

. .. .bashrc Desktop Documents Maildir Music Pictures public_html textfile Videos 

The -a that you used is called an option. It tells a program that you want it to do something different to the default. The default for ls is to list only those files which do not begin with a ".". Think of the -a option as meaning all, then ls -a means list all files in the current directory.

Now for another option for ls. Type:

ls -l


drwxr-xr-x 2 jimmy progsoc-users 4096 2010-02-16 13:37 Desktop
drwxr-xr-x 2 jimmy progsoc-users 4096 2011-01-26 08:04 Documents
-rw-r--r-- 1 jimmy progsoc-users 758 2011-03-01 16:52 textfile
drwxr-xr-x 2 jimmy progsoc-users 4096 2011-02-16 12:26 Videos

What does all this mean? Well, let's take the file called textfile as an example. The important bits are the hyphen thingies on the left, which are called permissions (more on them in a second), the name jimmy, which tells you who owns the file you are looking at and 758 is the size of the files in bytes. The next thing is the date and time that the file was last modified and finally we come to the name of the file we are looking at, in this case textfile. The -l option is called the long option because of all the information it gives you.

The great thing about options is that you can combine them. What do we do if we want to look at all of the files' information? We combine -l and -a! Groovy! Let's do it! Type:

ls -la

You should get something almost like this:

drwxr-xr-x 2 jimmy 		progsoc-users 4096 2010-02-16 13:37 .
drwxr-xr-x 2 progsoc-users      progsoc-users 4096 2010-02-16 13:37 ..
-rw-r--r-- 1 jimmy 		progsoc-users 1778 2011-01-26 16:51 .bashrc
drwxr-xr-x 2 jimmy 		progsoc-users 4096 2010-02-16 13:37 Desktop
drwxr-xr-x 2 jimmy 		progsoc-users 4096 2011-01-26 08:04 Documents
-rw-r--r-- 1 jimmy 		progsoc-users 758  2011-03-01 16:52 textfile
drwxr-xr-x 2 jimmy 		progsoc-users 4096 2011-02-16 12:26 Videos

The first two lines are directories, as you can tell because their permissions start with a d. The "." always means your present working directory (remember pwd?) and ".." means the directory above this directory (just like in cd ..)

Creating and Moving Directories

The two commands for manipulating directories are mkdir for creating directories and rmdir for removing directories. Now for some example uses. Make sure you are in your home directory because you cannot create subdirectories in a directory that you do not have write permissions in. Try these:

mkdir test_dir
cd test_dir
mkdir another_dir
cd ..
rmdir test_dir/another_dir
rmdir test_dir

In order: we created directory test_dir, moved into the new directory, created a sub- directory called another_dir. Then we moved back up out of test_dir and used the path to another_dir in the rmdir command to erase the subdirectory. Finally we removed the first directory we created. If you ever get an error message like No such file or directory when removing a directory it means you may have mistyped the file name.

If you want to delete a directory and all the files and subdirectories it contains you can use rm -r followed by the directory name. This will recursively descend the directory tree starting at the directory you want to erase and erase all subdirectories and files. There is no second chance when you do this, everything is gone forever so be really sure you want to use this. The -r option command is quite common in UNIX commands that you use to manipulate files and directories, as you will see.

Copying and Renaming Files

As part of your powers to manipulate files UNIX gives you the ability to duplicate and rename files and directories in just two commands. To duplicate you use cp and to rename mv. mv can also be used to move files between directories without creating superfluous copies. To use both commands you simply pass it the source filename and the destination filename. Here we go:

cp /etc/X11/Xsession Xsession
mv Xsession .xsession
cp .xsession virgin_sacrifice

You may want to use ls -la between commands to see how the changes show up. What we just did: copied a file called Xsession lurking in a directory called /etc/X11, then we renamed it .xsession using mv. We could have done this in one step with cp /etc/X11/Xsession .xsession but we didn't because I needed an example of using mv. Finally we duplicated .xsession within the directory. We did this so we could introduce you to the rm command.

Erasing Files and Directories

To erase things under UNIX you use the command rm which was mentioned briefly in the section on directories. Be careful with this command because although file recovery methods do exist for UNIX, there is no guarantee that they will recover your file(s) in one piece. Now a little example of using rm.

rm virgin_sacrifice

And that's how easy it is to use rm.


Permissions are another important part of UNIX -- they allow you to control other users' access to your files and directories. For any file you have you can control who can read it, write to it or execute it. Permissions are divided into three sets: permissions for the owner ofthe file, permissions for users in the same group as the owner and permissions for everyone else on the system. You are in group progsoc-users along with all the other ProgSoc members on the system. There are other groups called things like progsoc-admin, www-data and other. How can you find what groups you belong to? Try the command id. It tells you all sorts of exciting and useless information including your User Identification Number (abbreviated uid), the name of the group you are currently in and a list of all the groups you belong to. Jimmy get this when he uses id:

uid=2116(jimmy) gid=2000(progsoc-users) groups=2000(progsoc-users),2001(progsoc-admin)

Yours will be slightly different.

For all files three sets of permissions are set up. Permissions for the person who owns it, permissions for everyone in the same group as the owner (group permissions) and permissions for everybody else. For each permissions set there are three modes: read, write and execute, appearing as r, w and x respectively. If the letter appears in the right spot, then that permission is set.

The first character is normally either a d or a "." and has nothing to do with permissions. Next is space for the three modes for the owner of the file. If you look at the above example the modes for the owner (me) for textfile are "rw-". The r means that Jimmy can look at the file and the w means that he can change it in any way he wishes. The next character is a hyphen which means Jimmy doesn't have execute permission on textfile. Which is just as well really, as it is not an executable, so even if he could execute it nothing would happen.

The next three characters are the modes for everyone in my group. If you look back in this tutorial to where Jimmy used the id command you will see that he is in the group progsoc-users, along with everyone else in ProgSoc. Thus you could all read this file but you could not change it or execute it. The final three permissions are for everyone else on the system, and Jimmy's such a nice, friendly kinda person that everyone can read his copy of the textfile, but no-one can write to it except him and no-one can execute it. The permissions for .bashrc are the same.

This brings us to directory permissions, which are important as they define what everyone can do to the files in that directory. If someone has write access (w is set) to a directory they can make changes to it, including erasing files or adding files to the directory. The command you use to change the permissions on a file or directory is chmod which stands for change mode. chmod takes three sets of arguments: which group's permissions you are going to change (any combination of user (owner), group and others), a + or - to say if you are setting or resetting the permission, which permission you are going to change (any combination of r, w and x) and at the end you list the file or directory you wish to change.

The shape of the command is like this:

chmod [ugo] [+-] [rwx] filename

After you use chmod you can use the ls -l command to see what changes you have made to the permissions fields. Here now are some examples of chmod for you to try in your home directory. You may want to use ls -l after each chmod to see the results.

chmod go-rwx textfile
chmod go+r textfile
chmod ugo+x textfile
chmod go+r .
chmod go-r .

The examples, in order: make textfile unreadable, unwritable and unexecutable to everyone except you, make textfile readable by everyone besides you, make textfile executable by everyone including you, make your home directory readable by everyone and stop everyone from reading your home directory. Just remember when changing permissions on files that you must be the owner of the file or directory to be able to change its permissions. Also, never make your home directory unreadable by yourself (ie chmod u-r .) as you will not be able to login.

Glob-o-rama! Or, Working With Multiple Files

You will one day want to copy lots of similar files -- ie, you'll want to copy all your Java files from directory programming to directory eatme. All Java source files have an identical suffix of .java, C files have the extension .c and so on ... Rather than specifying each filename individually, you could use "globbing."

Globbing is a silly UNIX word that means "referring to multiple files at once" -- Pattern matching, but that's a bit technical. The best-known example is *, the "asterisk" or "splat" character. UNIX takes this to mean "any sequence of more than one character."

Some examples:

  • *.e Matches all files ending in .e - abcd.e, potato.e and file .e itself.
  • t*a* .e All files beginning with t, ending with .e and having the character a in between.

So cp *and* *butnot* would make a copy of the file johnandellen named johnbutnotellen - it will do the same for all other files containing the word "and". If you didn't have the asterisks around butnot (cp *and* butnot) all files containing "and" would be copied to a single file butnot, which is probably not what you wanted.

Braces ({, }) indicate alternatives: the string Pet{er,a} means Peter and Peta. The alternatives are separated by a comma: ie {and,if,but,not}. rm *.{p,pdb} will delete all files ending with .p or .pdb.

Square braces [ and ] are used to indicate ranges: the expression [ ai ]llusion will match illusion and allusion.

More examples:

  • cp fre{ida,d} /home/progsoc-users/jimmy will copy the files fred and frieda in the current

directory to directory /home/progsoc-users/jimmy.

  • mv /home/progsoc-users/jimmy/{m,br}aniac* . will move (copy plus delete the original copies) the files

maniac, maniacally} and <tt>braniac from directory /home/progsoc-users/jimmy to your current working directory. (Fullstop . means "your current directory".)

  • rm ~hhefner/ s[ea]x[oy]* will remove files sexy and saxon and sexo-thingies from directory /home/hhefner - his home directory, indicated by the tilde ~ .

There are additional examples in the Vi section of this manual Basic Regular Expressions.

The characters

* ~ . \ [ ] { } ^ $ 

all have special meaning to UNIX (And similar meanings in Vi and suchlike). Don't use them in filenames. If you have, or you want to use a special character as itself and not as a glob, put a backslash beforehand. The expression


evaluates to


If you want the backslash itself, use two:

\\\\ matches \\.

Globbing is awesome. We suggest you experiment secretly at night, and read the sh man page (man sh) and the Erotic Fantasy chapter on shell programming later in this manual.

Pipes, or Jetpack 101

One of the basic design policies behind UNIX commands is that they read from standard input (stdin) and write to standard output (stdout). stdin and stdout, unless otherwise specified, are the keyboard and the terminal screen respectively. The clever thing is that stdin and stdout can be specified as other things, such as files, or even output of other commands. Huh? What we just said was that the output from command1 can be used as the input to command2. Even cleverer, the output from command2 could be piped into command3. So? UNIX is built up of simple commands which do one thing, but do it well. Used in combinations they become quite powerful[4].

To pipe the output of one command into another you place the | symbol between the two commands on the command line. Here is an example of a simple pipe you can use to count the words in a file:

cat textfile | wc

The result of this command will be three numbers: The number of lines, the number of words and the number of characters in the file. What did we just do? cat is used to write a file to stdout. If you executed cat textfile by itself (try it) textfile would be displayed on your screen. Using | we redirected the output from cat's stdout into wc's stdin. All wc does is count the number of lines, words and characters in the file passed to it. In the above example we didn't give wc the name of a file to work on so it knew it had to read from stdin. If we had wanted to we could have simply typed wc textfile.

Now you get to do some work. Here is a pipe:

who | sort | cut -f1 -d\ | uniq | wc | awk '{ print \$1 }'

What did you get? If you typed it in correctly you will get back one number which is the number of users on the computer you are using. How does it work? That's for you to find out[5].

Using Remote Machines

You can log into one UNIX machine from another. Neat huh? There are lots of reasons why you might want to do this -- perhaps the machine you are currently logged into is being slowed down by thousands of muddling first years compiling Java. Or, more likely, there is a program that you need to use which is not available on your machine, but is available on another.

The ssh[6] command allows you to do this. She is your friend. Treat her well and she'll be good to you.

To invoke her, type something like:

ssh machinename

The machinename will most likely be a short machine name like muspell. It could also be a fully specified network name like or an IP address (eg:

After typing in the ssh command it usually asks you for your password. If you get it right you'll be allowed onto the remote machine. Any command you type from then on will be executed on the remote machine. The UNIX prompt normally tells you where you are.


The following example demonstrates logging into niflheim from kali.

user@kali-desktop$ ssh niflheim
user@niflheim's password:
Linux niflheim 2.6.31-17-generic-pae #54-Ubuntu SMP Thu Dec 10 17:23:29 UTC 2009 i686

To access official Ubuntu documentation, please visit:

0 packages can be updated.
0 updates are security updates.

Last login: Wed Jan 13 15:53:53 2011 from

After you're finished using the remote machine, type the logout command[7] and you will be back to your original machine.

user@niflheim$ logout
Connection to niflheim closed.

If you have a different username, you can log in on the remote machine by using the -l username option to ssh, ie:

ssh -l username machinename

ssh username@machinename also works.

Write and Talk

There are two direct ways of speaking with friends at other terminals:[8] WRITE (one way communication) and TALK (two-way). There is a third, frighteningly dangerous method called Internet Relay Chat, or IRC, but we won't discuss it here.

First, the mesg command. This stops people from communicating with you---you don't even see requests. Use mesg n at the prompt to cut off communication[9]

mesg y means you're taking messages

again[10]. Email is received regardless of mesg status.


To use WRITE, type write username at the command prompt. The receiver---the username you specify---will see

message from yourname@yourmachine

in their login window and their terminal will beep. If the receiver's login window is obscured---closed or covered by other windows---they may miss your message. If the connection is refused, the receiver is mesg n. Send Email instead.

If you did connect, type away. Each time you hit \RETURN, the text you've typed will appear in their window. Use CTRL-C to finish. The receiver will see EOF ("End of File").

If they want to reply, they have to WRITE back to you ( write~yourname) or use TALK.


To use TALK, you'll need to know which machine the receiver is using. Most users remotely logged onto ProgSoc machines will be found on niflheim. You could use UNIX commands like FINGER or RUSERS to find the server, but it's usually faster to pick one randomly.

This time, enter talk username@machine at the prompt. (This means "talk username at machine.")

If the receiver is mesg n the window closes abruptly. Again, you'll have to use Email until they return to communication.

Otherwise, your screen splits vertically in two and you'll see the message

[Waiting for your party to respond].

The receiver will see:

Message from Talk_Daemon@niflheim at 16:14 ...  
talk connection requested by user@niflheim.   
talk respond with:  talk user@niflheim   

In your case, user@niflheim is be replaced by yourname@yourhost. If the receiver wants to talk, s/he enters talk~yourname@yourhost. Their screen also splits vertically and you'll both be told [Connection established]. Whatever you type from now until termination will be seen by the receiver and vice versa. CTRL-D ends conversation. If something happens to your screen, such as other users, use CTRL-L to redraw the screen.

This response

[Checking For Invitation On Caller's Machine]

means TALK isn't working---for the moment at least. Use Email.

Printing Files on an LPR Printer

Although ProgSoc does have a printer at time of publication, it is not connected to the club's network, so this section would be of little use on the club's computers. However, if you happen to find yourself in an antiquated UNIX network environment in which only the printing of text files is permissible -- that is, you are using a Line Printer Remote (LPR) protocol printer, instead of a Common UNIX Printing System (CUPS) printer that has largely superseded, is backwards-compatible with, and is more commonly used than LPR -- then this section might be of some use.[11]

Use the lpr command to print files:

lpr -Pprinterid filename

An example: to print file johnboy to a printer (let's call it blue-printer), use

lpr -Pblue-printer johnboy

Only print text files. Executable, graphics or other binary (not-text) files are not only unreadable by humans but incredibly big, which wastes paper, printing time and ruins the printer. Sometimes, when you produce a typescript there will be unprintable characters in it. All the printer will produce is " binary file, unprintable", or something similar. You should use col -b to remove them. The other way is to use Vi or ex and use regular expressions to find and delete control characters[12].

If you've accidently sent a bad file to the printer, squirm in terror --- or use the lprm command to delete it from the queue (see below).

Looking at the Printer Queue

If other people are printing, you have to wait your turn. lpr actually puts your file in a print queue --- don't expect instant printing, especially when the printers are in high demand. The lpq command displays the queue:

lpq -Pprinterid

There is a separate queue for each printer. Your output will look somewhat like

lp is ready and printing
Rank   Owner      Job  Files                                 Total Size
active leroy      563  glob.tex                              6627 bytes
1st    jcolville  580  playtime.article_on_canals           12452 bytes
2nd    jcolville  631  playtime.ASCII_picture_for_article   97356 bytes

To remove your file from the queue, you'll need to know the job number --- in this case, jcolville has two jobs: numbers 580 and 631. Job 580 was submitted before 631, as it's closer to the active (printing) job.

To remove a file from the queue, use

lprm -Pprinterid jobnumber

Mr Colville would kill his first job on printer blue-printer with

lprm -Pblue-printer 580

Using lprm without a job number kills all requests from your userid in the queue. Mr Colville could replace his earlier command with lprm -Pblue-printer, killing jobs 580 and 631 in one savage purge.

Using Manual Pages

And finally, for almost all commands on the system there is some online information telling you all about them. To access this information you use the man command like so:

man man

This will give us the manual page for the man command. The information is displayed using another command called more[13], which you can use when you want to browse through long documents. To use more you only need to know three letters: b, f and q. Use f to move forward through the document a page at a time and b to move backwards through the document. When you're finished you press q to quit[14].

If you want to do something but you don't know the command you can try searching by any keywords you can think of. To do this use man -k followed by the keyword. Try this example:

man -k manual

This will tell you about xman which is a graphical interface to man.

You will probably find at first that reading the online manual is not very easy. In the beginning you will find it easier to find someone to answer your question for you rather than reading the manual, but as you learn more it will become more difficult to find someone who can answer your newer, leaner, meaner questions and you will have to read the manual pages for yourself, eventually. Maybe not.

Control-Key Shortcuts

Here are some two-finger combinations[15] that can save you some time. You might not discover these for a year or two unless you

  • are very curious
  • watch someone else and think "Hey! What key was that?"
  • log in one day to find your arrow keys are dead due to a misconfiguration
Key Combo   General Usage
Ctrl-A Jump to beginning of line (home key)
Ctrl-E Jump to end of line (end key)
Ctrl-B Back one character (left arrow)
Ctrl-F Forward one character (right arrow)
Ctrl-P Previous line (up arrow)
Ctrl-N Next line (down arrow)
Ctrl-H Delete the character to the left and move left (in other words, the backspace key)
Ctrl-K Cut from here to the end of the line
Ctrl-W Cut from here to the beginning of the line
Ctrl-U Clear entire line
Ctrl-L Clear or refresh screen (the boss key!)
Ctrl-I Tab key (very underappreciated by some)
Ctrl-G The "bell" key, to recreate a system beep
Ctrl-X Execute (context-specific and probably powerful)
Ctrl-S Stop something scrolling
Ctrl-R Resume something (usually scrolling, but "any key" is usually okay)
Ctrl-Q Resume scrolling (when Ctrl-R doesn't do it)
Ctrl-M Return key
Ctrl-C Cancel this operation, in an abnormal way
Ctrl-D Cancel this operation, in a normal way; close this session; finish this file; and so on
Ctrl-Z Suspend this operation. Probably the most powerful since the OS likes to keep this one to itself so you can multi-task programs. Upshot of which, is that it's more often available than Ctrl-C.

Quitters Never Prosper

It's often said that you learn far more by experimenting with programs than you ever will by reading the manual. Usually this is said by people trying to rationalise their instinctual fear of cracking open a book and reading. As a service to these people we present instructions for quitting a great many applications --- because it would be a shame if you spent half an hour `playing' with vi and getting nowhere, and then had to refer to the chapter on vi just to quit.

What it is How to quit it
your shell Type exit
vi ESC :wq! to save and quit
ESC :q! to quit without saving
emacs CTRL-x, CTRL-c, which will prompt to save any unsaved files
X Find the Logout option in your GUI's menus
a stuck application From a terminal type ps, find its process ID and type kill -9 pid
many command-line programs CTRL-c
a stuck command-line program Try CTRL-z; if you get your prompt back proceed as for `stuck application' above
Windows Type CTRL-alt-del and click Log Out
a Windows application CTRL-q
a Windows application ALT-F4
a Macintosh application APPLE-Q
a Macintosh dialog APPLE-.

These were selected to get you out of whatever you're in with a minimum of fuss and confirmation dialogues. Most applications (and vi is famous for it) have more than one way to quit, as described in their manuals -- or so we've heard.

  1. And which flavour(s) of UNIX do(es) not, you tell us?
  2. And only the simple penknife with two short blades; you are yet to be introduced to the Swiss Army knife.
  3. Replacing the completely hypothetical username -- it's not as if there's an actual ProgSoc member with that account ;) -- with your username.
  4. Sort of like those robots in Japanese cartoons made of little robots which all join together to form giant caterpillars and the like.
  5. Try extending the pipeline one command at a time. See what who does by itself, and so on; read the manual entries for the commands. By the time you work through the example, especially the last command awk, you will be well on your way to mastering UNIX.
  6. As in secure shell.
  7. Or anything you find in the entire chapter devoted to logging out, really.
  8. Apart from shouting, sending paper planes, sign language, semaphore, footsies under the table, passing messages through potentially hostile networks of other students and random passers-by, telepathy, or writing messages on some non-essential body part like a toe, chopping off the toe with a meat cleaver and throwing it across the room accompanied by screams and shouts of "Ick!" Let's face it, you can probably get more into a TALK window than you can write on a toe, and you won't lose your balance afterwards.
  9. Do this when compiling for assignments, markers don't want to see pages of talk requests when checking your compilation log.
  10. xvt, if you use it, has an unfortunate habit of starting out with mesg n set. To fix this, put mesg y in your .cshrc file (how to do this is discussed later in this manual). xvt used to be the default terminal application, but xterm has replaced it.
  11. Can you tell how old this section is!?
  12. The regexp :1,\$ s/\^{}V\^{}M// will remove DOS new-line characters.
  13. or sometimes another program known as less. After a while you become skilled at encountering these sorts of program names without even so much as groaning.
  14. If you do want to browse through long documents we recommend using less which is exactly like more but nicer. more has a nasty habit of exiting as soon as it reaches the end of the file, as you will see when you use man, whereas less must be explicitly told to quit by pressing "q".
  15. Note that this list is not comprehensive across various programs, environments and terminals.
Personal tools