next up previous contents
Next: Editors Up: Finding Your Way Around Previous: The Unix File System   Contents


Unix Commands

In this section, some simple forms of a few Unix commands will be outlined. If you want to know more about Unix commands, there are many good tutorials available in bookshops and on the WWW. If you install Linux, your CDROM or book should have some tutorials.


This command lists the usernames of all who are logged in.

turing % who
jdoe        ttyp0       Sep 02 09:16
fflintst    ttyp3       Sep 17 15:45
ddawg       ttyp2       Sep 04 11:41
sdoo2       fluke:0     Sep 17 10:11
norm        ttyp7       Sep 17 16:22
comp131     ttyp8       Sep 17 15:43
comp284     ttyp5       Sep 10 15:29
ltorvald    ttyp6       Sep 16 15:57
wflintst    ttyp9       Sep 05 17:20
brubble     erdos05:0   Sep 17 15:53


Even more interesting is the w command. It shows you who is logged in, where they are logged in from, and what they are doing!

turing % w
14:21  up 16 days,  5:34,  10 users,  load average: 1.42, 1.50, 1.44
User     tty     from             login@    idle   JCPU   PCPU what
jdoe     p0      boole            09:16    26:41 139:41      7 -zsh
fflintst p3      bedrock          13:52               5      5 talk brubble
ddawg    p2      fermat           11:41     1:40   8:32      6 -tcsh
sdoo2    p7      fluke            14:16        2               vi file.h
norm     p8 15:43     2:07  11:32   1:03 ncftp ftp.sun
comp131  p5      germain          15:29    23:44               -csh
comp284  p6      godel            15:57    23:13               -tcsh
ltorvald p7      kernel           16:22                        gcc 
wflintst p9      riemann          17:20    16:53   3:42      3 -tcsh
brubble  pa      bedrock          13:52                        talk fflintst


Returns your username.

turing % whoami


Prints the current date and time.

turing % date
Tue Sep 16 17:07:26 EST 1997


Lists all the files in your current directory.

turing % ls
Deb         cshrc.csh   dat4.Z      hons        private

Some Unix commands may take option flags which alter the way the command works. These flags are usually optional. For example, the basic form of ls is demonstrated above. However, if the command is given with the option -l (for long), the command prints as shown below:

turing % ls -l
total 64
drwx------  2 fflintst       1024 Nov 20 09:34 Deb
-rwxr-xr-x  1 fflintst        580 Nov 16 00:55 cshrc.csh
-rw-------  1 fflintst       1101 Sep 29 13:05 dat4.Z
drwxr-xr-x  3 fflintst       1024 Jan  4 11:45 hons
drwx------  2 fflintst       1024 Jan 29 11:29 private

The option -a (for all) lists all files including `invisible' files. You can also combine options. For example: ls -la.

Some Unix commands take command line arguments which may be either optional or mandatory. For example cal prints out a calendar for either a month or a year, but MUST be given the year of the calendar that is required.

turing % cal
usage: cal [month] year
turing % cal 12 1957
    December 1957
Su Mo Tu We Th Fr Sa 
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

Many Unix commands accept both arguments and flags. For example, if ls is provided with a list of files, it will only return information on those files that exist.

turing % ls cshrc.csh
turing % ls -la cshrc.csh
-rwxr-xr-x  1 fflintst        426 Oct  9 14:45 cshrc.csh
turing % ls
Deb         cshrc.csh   dat4.Z      hons        private

Manipulating Files

Assume that in your home directory there's a file called test1. The examples below will manipulate this file with the cp (copy), mv (move), and rm (remove) commands.


Syntax: cp sourcefile destfile

Makes a copy of sourcefile which is then named destfile. For example, to make a copy of test1 called mycopy:

turing % cp test1 mycopy

If you now do an ls, you should have two files, test1 and mycopy.


Syntax: mv sourcefile destfile

Renames, or moves sourcefile to destfile. For example, to rename mycopy to newcopy:

turing % mv mycopy newcopy

Again, do an ls to check your result.


Syntax: rm file

Removes file. For example, to remove newcopy:

turing % rm newcopy

Note that once a file is removed, it is gone. There is no `un-remove' feature. Some Unix systems however, provide del and undel commands.

Directory Manipulation

These commands are used to move around, create and delete directories.


This command shows which directory you are in.

turing % pwd


This command is used to change from one directory to another. For example:

turing % cd ../brubble

changes up one directory, and then down into brubble. If you enter

turing % cd

you will be back to your home directory, i.e., the directory where you are when you first login. This is the default behaviour of cd. This is, if no directory is specified, it changes directory to your home directory. Try:

turing % cd ..
turing % pwd
turing % cd
turing % pwd

A very useful abbreviation13 which means `home directory of', is ~. For example, if you typed cd ~brubble you would change directory to the home directory of user brubble. A ~ by itself just means your home directory. So the commands cd and cd ~ do the same thing.

See also Section 5.8 where it is explained how to use ~ to find the various unit home directories on UNE systems.


This command is used to create a directory.

turing % mkdir tute1dir


Removes a directory.

turing % rmdir tute1dir

If you try to remove a directory that contains files, you will be given an error message.

Displaying Files


Syntax: cat file

The standard command with which to display a file.

turing % cat file1

If a file is longer than one screen, you will probably want to use less instead. It displays a file one screen at a time.


Syntax: less file

less14 will display the first page15 of a file and then wait until the user instructs it on what to do next. Some of these commands are:

RETURN move display down one line
b move display back one screen
SPACE move display forward one screen
q quit displaying the file

Printing Files

These commands show you how to print files on UNE systems. If you are an external student, there is no point in printing files on these printers as you cannot collect the output. If you run Linux on your home system, then these commands will be similar to the ones you will use on that system.


Syntax: lpr file

Queues file to be printed on the default printer. The option -Pprintername sends the file to the queue on printer printername. For example, lpr -Pmlab1 file sends file to the printer mlab1.

turing % lpr file1
turing % lpr -Pmlab1 file1


Syntax: lpq

The amount of time it takes for your file to be printed, depends on the size of the queue before it. To find out the size of a printer queue, use lpq for the default printer, or lpq -Pprintername for printer printername.

turing % lpq
mlab1 is ready and printing via network
Rank   Owner      Job  Files                                 Total Size
active fflintst    80  file1                                 733 bytes

Manual Pages

A copy of the Unix manual is kept on the system, and it is possible to have the documentation for most commands displayed by the man command. The example below illustrates how to use man to display the documentation for the cat command. This example has been truncated.

turing % man cat

  cat - Concatenates or displays files

  cat [-benrstuv] file ...  | -

  The cat command reads each specified file in sequence and writes it to
  standard output.

Man pages are intended to be a comprehensive reference for most Unix commands. They are not intended as tutorials and as such can be hard to understand for novice users. As your experience grows, so too will your appreciation for man pages.

next up previous contents
Next: Editors Up: Finding Your Way Around Previous: The Unix File System   Contents
WWW Data 2003-03-07