This page is for the novice or intermediate UNIX user and gives a brief description of each command and some examples to clarify its use. For more detailed information, refer to the man pages.
A intermediate user of UNIX should know all of the things mentioned in the index below. UNIX has many more commands and the commands listed have many more options which have been ignored for simplicity.
Hidden Files | syntax | Redirection | a2ps | cal | cat | CC | cd | chmod | cp | date | diff | du | elm | finger | ghostview | grep | head | ln | logout | lp | lpstat | ls | man | mesg | mkdir | more | mv | od | passwd | pr | ps | pwd | quota | rm | rmdir | scripts | setenv | sort | tail | talk | tin | who | wc
For corrections, please contact ScienceIT
Files starting with a dot (“.”) are hidden files. Doing ls will not show these files. You must type ls -a . Here are some examples.
C-Shell personalised command set.|
Edit or create this file as a normal text file. The commands entered will take effect whenever a new session (Window) is started. Type source .cshrc to effect the changes immediately.
|.login||Same as .cshrc but only for the first process. Type source .login to effect the changes immediately.|
|.signature||If it exists, its contents will be included at the bottom of every outgoing mail message (before you edit it).|
If it exists, its contents will be displayed after the usual “finger” information when another user issues the ‘finger’ command on your user_id. Make sure the permission on the file is readable by all.|
(ie. chmod 644 .plan) .
Some UNIX command-line syntax:
|;||A semicolon separates two commands on the same line. eg. cd mydir; ls -al|
|&||Used after a command, an ampersand tells the system to run the command in the background and return immediately for a new command. eg. xclock & (opens a clock window)|
||||Used between two commands, the pipe sends the output of one command into the input of another. eg. cat myfile1 myfile2 | lp (not to be confused with redirection)|
|*||Means “any string of 0 or more characters”. eg. cp * Backup Copy all files in current directory to Backup directory.|
|?||Means “any string of exactly 1 character” eg. cp prog?.c Backup Copy all files in current directory, such as prog1.c, prog2.c, etc, to Backup directory.|
Matches 1 character to character_list or range|
eg. a.cpp Matches all files a0.cpp, a1.cpp, a2.cpp or a3.cpp
eg. a[0-3].cpp Same as above
- command > file_name Send output to file_name instead of stdout
- command < file_name Take input from file_name instead of stdin
- command >> file_name Append output to file_name instead of stdout
fred < input.txt > output.txt
Run fred using input.txt instead of the keyboard and send output to output.txt instead of the screen.
Alphabetic list of common UNIX commands
Stops program execution
Pauses program execution. Type bg to continue in background or fg to resume in foreground. See “ps” command to keep track of background processes.
Stop display of long output. See ^q.
Restart display after a ^s.
Run command in background.
Example: xclock &
a2ps <options> file_name | lp
Convert text file to postscript format.
Example: a2ps -2 -F8 -H'Assigment 1' myfile | lp
cal [month] [year]
Display a monthly calendar.
pompeii:~:1 % cal April 1997 S M Tu W Th F S 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 pompeii:~:2 %
cat <options> file_list
Join files together (conCATenate)
C++ compiler. (Use lower case ‘cc’ for straight ‘C’ code.)
CC -o fred fred.c
CC -o fred.o fred.c
CC fred.c >& output_file_name
cd / Root directory
cd fred Change to directory fred from current directory.
cd .. Parent directory
cd Your home directory
chmod mode file_list
Change the mode or access permissions of a file.
To see the current permissions, use ls -l . You will see something like this:
drwxr-xr-x 2 s9999999 3ug 512 Mar 3 13:58 fred.c
The characters on the left hand side are the permissions. The first character is a ‘-‘ if it is a file, ‘d’ if it is a directory. The next 9 characters are the read (‘r’), write (‘w’) and execute (‘x’) permissions for the owner, the owner’s group and the world (everyone else).
drwxrwxrwx 1222333444 1: Directory indicator: d for directory, - for ordinary file 2: Owner permissions:r for read-access, - otherwise w for write-access, - otherwise x for executability, - otherwise 3: Group permissions: ditto 4: Others' (world) permissions: ditto
The mode can be either a three character code or a three digit octal code. The three character code consists of:
1. who ==>u for user, g for group, o for others or a for all. 2. operation==>+ for adding permission, - for removing permission 3. permission==>r, w, x as above.
The three octal digit code sets all 9 permission bits at once, counting them as bits. That is, 700 sets the first 3 bits to 1 and all others to 0. In effect, this gives the owner of the file read, write and execution access and denies these to everyone else.
chmod 711 html Set permissions to 111001001, ie rwx–x–x, ie Owner can do anything, including executing this file, and others can execute but not read or change this file. This is commonly used for html directories. Opening a directory is, in effect, executing that directory.
chmod 644 index.html Set permissions to rw-r–r–, ie Owner can read or write the file and all others can read it only. This is commonly used for html files.
chmod u+x index.html Add execution permission to “index.html” file.
cp <options> source_file destination_file
Copy one file to another.
cp file1 file2 Creates a copy of file1 in file2.
Display date and time. A possible option is “-u” giving the Universal Time (Greenwich Mean Time).
pompeii:~:1 % date Mon Jun 2 16:10:50 EST 1997 pompeii:~:2 % date -u Mon Jun 2 06:12:56 GMT 1997 pompeii:~:3 %
Checks for differences between two files.
“diff” outputs the differences:
du <options> [dir_list] [file_list]
Displays disk usage in blocks of 1000 bytes (not 1kB). eg 129809 is shown as 129!
Electronic mail facility. (see also “pine”)
eg. elm -f Mail/letters Opens up the folder “letters”.
in “elm”, each message has a status on the left hand side:
To read a message, press “Enter”. This displays the contents of the current message. If it does not fit on a page, press “space” to scroll a page at a time. When finished reading press “i” to return to the index. “d” deletes the current message, “q” exits elm.
To compose a new message, type “m” for mail.
If you receive a message and want to reply to the sender, just type “r”.
Displays details of all users currently logged on. If a user id is specified, That user’s details are displayed, including whether they are logged on, whether they have unread mail and their plan file.
“Ghostview” allows the user to see a postscript file which is not normally viewable with a standard text editor.
grep <options> pattern file_list
(Global Regular Expression Print) Display lines which contain pattern in file_list.
grep the *
grep "the dog" *
head [-no_of_lines] file_name
Display specified number of lines (10 if omitted) from top of file_name. This would be used for very long files which might contain rubbish half way through the file. This means you can just look at the first 100 lines or so.
head -30 fred.c
ln <options> directory_name pretend_path_name
Create a symbolic link. Allows renaming of long path names to a short name. It creates a file name in your pwd so the ‘ln’ command does not need to be in your .cshrc file. The link can be deleted just like any other file name.
Logs the user out of the system. See also CONTROL_D (^d).
lp <options> file_list
Send files listed in file_list to default printer.
pompeii:~:4 % lp test1 request id is e6a114-laser-18401 (1 file(s)) pompeii:~:5 % pompeii:~:11 % lp -de6a119-laser test1 request id is e6a119-laser-18405 (1 file(s)) pompeii:~:12 %
Display print job queue.
pompeii:a3:16 % lpstat -o e6a114-laser-452 pompeii.ics.mq.edu.au!s3036050 2828 Jun 10 13:46 on e6a114-laser
Note the number (452) after the printer name (“e6a114-laser”). This is the Job Number and can be used to cancel the job.
ls <options> [file|directory]
Display list of files in current directory.
man [-sXX] command_name
Display system documentation relating to command_name. Some commands or functions are in different sections. Use the -sXX option to access the specific section, where XX is the section number. “man” will look for the first occurence of the command_name.
man -s3S printf
Controls the “talk” command.
Create a new directory.
Display file on screen one page at a time.
od <options> file_name
Display binary files in octal mode. This can be used to display the contents of a file which contains unprintable characters.
mv <options> [old_path/]file_name [new_path/]/new_file_name
Move file_name file to new_file_name file. Can be used to rename a file or move a file from one directory to another.
Change your password
Format a file to prepare it for printing.
pr -F file1 file2 > file1_file2_side_by_side This produces an output with file1 and file2 side by side. This makes it easier for comparing two similar files.
Display list of current processes.
pompeii:~:6 % ps PID TTY TIME CMD 17808 pts/135 0:00 ps 11079 pts/135 0:00 tcsh-6.0 pompeii:~:7 %
Present Working Directory (your current directory).
Display your current quota. You are normally allocated about 8MB of memory to work with. This command will show you how much you are currently using and how close you are to exceeding your quota.
pompeii:~:1 % quota -v Disk quotas for s9999999 (uid 6163): Filesystem usage quota limit timeleft files quota limit /disks/pompeii/home 6667 8000 8500 829 0 0 pompeii:~:2 %
Delete files in file_list.
Remove empty directory
setenv PRINTER printer_name
Set printer_name as the default printer. “setenv” by itself will display all the environment variables which affect the behaviour of you terminal session.
sort <options> [field_specifier_list] file_list
Options:(Fields are separated by blanks.)
tail [-no_of_lines] file_name
Display specified number of lines (10 if omitted) from bottom of file_name. This would be used for very long files which might contain rubbish half way through the file. This means you can just look at the last 100 lines or so.
Examples: tail -30 fred.c
Visual communication with user_name. ^c by either party will terminate connection.
News reader. Allows access to news-groups.
Displays information about who is using the system. (“w” works also).
wc <options> file_list
Count number of words in the files in the list.
Edit a new text file and type commands as required. Then make this text file executable (see chmod). You can then type the file name by itself and you have thereby created a new command.
- Tells the system to ignore text that follows (ie. a comment)
- set variable = string_value
- Set variable to a value
- alias dummy_name real_command
- Create new command from old.
- alias dummy_name
- Display real command corresponding to dummy_name
- Display aliases already set
- unalias dummy_name
- Remove alias dummy_name
- echo message
- Display message on screen (if message starts with dollar and it is not a variable, precede it with (slosh))
- echo $variable
- Display value of variable on screen
- Preset variable containing home directory.
- Contains path to be searched for commands