unix_tut
unix_tut
Table of Contents
A UNIX Commands Reference Tutorial...........................................................................................................1
Introduction..........................................................................................................................................................1
Getting Started.....................................................................................................................................................1
− A −.....................................................................................................................................................................5
− B −.....................................................................................................................................................................6
............................................................................................................................................................................7
− C −.....................................................................................................................................................................8
− D −...................................................................................................................................................................12
− E −...................................................................................................................................................................14
− F −....................................................................................................................................................................15
− G −...................................................................................................................................................................17
− H −...................................................................................................................................................................18
− I −....................................................................................................................................................................19
− J −....................................................................................................................................................................20
− K −...................................................................................................................................................................21
− L −...................................................................................................................................................................22
− M −..................................................................................................................................................................25
− N −...................................................................................................................................................................27
− O −...................................................................................................................................................................28
− P −....................................................................................................................................................................29
− Q −...................................................................................................................................................................32
− R −...................................................................................................................................................................33
− S −...................................................................................................................................................................34
− T −...................................................................................................................................................................37
i
A UNIX Commands Reference Tutorial
Table of Contents
− U −..................................................................................................................................................................39
− V −...................................................................................................................................................................40
− W −.................................................................................................................................................................42
− X −...................................................................................................................................................................44
− Y −...................................................................................................................................................................45
− Z −...................................................................................................................................................................46
ii
A UNIX Commands Reference Tutorial
By ©John N. Kostaras
Introduction
This tutorial stems from and enhances a manual I once read, “INTERACTIVE UNIX Operating System
Primer – Version 3.0” [1]. It covers both Unix and Linux releases. It is basically a quick reference of the most
common commands avoiding the bundle of information currently offered by the man command. For a more
complete reference, however, one should either use the man command or another more complete source.
Getting Started
Before you can start working with UNIX, you or your system administrator must have installed the system
and set up your login account. If your system is switched off, you must first boot the Unix operating system.
In a workstation normally, the computer where the operating system has been installed, is on 24 hours per
day, and a common user simply connects to the main computer via a terminal. If this is the case, once you
switch on the terminal, a screen asking for a login name appears:
Login:
If however the operating system is installed in a PC (e.g. a LINUX release), after you switch on the computer
the operating system is booted. If this is your case then you will see a number of strange messages appearing
on your screen before the aforementioned login screen appears.
Logging in
In the login prompt, type in your user identification name (ID), or login name, assigned to you and press
ENTER. After a user ID is entered, the system may request a password:
Login: johnPassword:
Type in your password (if you have been assigned one) and press ENTER. The password is not shown on the
screen so that no one watching at your display at that time can see it.If you have typed your login name and
password correctly the system displays the command prompt on the screen:
$
or something similar (# or %). The prompt indicates that the system is ready to receive information. You may
enter a command or run an application when the prompt is displayed on your screen. When you interact with
the UNIX operating system (shortly OS), the commands you type are processed by the command interpreter,
which passes your commands to the OS for processing and delivers the results to you. This interactive
command interpreter is called the shell.Each time you log in, the OS places you in your home directory. This
is your personal working area. Like the DOS OS, the UNIX OS consists of files and directories. A file is a
collection of data stored under an assigned name. Examples of files are a text document you type, an
executable program etc. This tutorial is also stored in a file with filename “UNIX tutorial.doc”. A directory is
a file repository. It exists only to help you organize your files into separate thematic entities. A directory can
contain other directories (or sub−directories) and files.
Logging out
After you have finished your work with the system, you must log out. Always logout when you are finished
using the computer, to prevent unauthorised use of your account. You can log out by one of the following
ways.
• You can hold down the CTRL key and simultaneously press d
• You may type the exit command at the prompt and press ENTER
• You may type logout at the prompt and press ENTER.
The OS will display the login: prompt, indicating that it is ready to accept a new login name.
If you are a system administrator you can shut down the system. Switching off the terminal display does not
shut down the system. In a PC however, you cannot simply switch it off. You first must shut down the OS.
Because UNIX is a multi−tasking OS, the computer can be running many different processes (programs) at
the same time. For example, you may be printing a file while at the same time you are editing another file. To
arrange for the computer to complete all the tasks that are currently running, you should shut down first before
switching off.To shut down the computer you must first login as a system administrator, or a user with system
administrator’s privileges. If you are then you can shutdown the system by entering the following command at
the administrator’s shell prompt (which is #):
# shutdown
and press the ENTER key. The system will ask you a number of questions like when should the system go
down etc. You should answer to these questions with a y for yes or a n for no. If you want however to
shutdown the system immediately without being prompted with questions you should add either now or –g 0
or –h 0 after the shutdown command at the prompt. After a number of strange messages on the screen, the
message:
System halted
appears and the system is halted. You can then switch off the computer.If you want to reboot the computer
you should enter –r 0 after the shutdown command.
Command syntax
In a UNIX OS, the user types a command followed by the ENTER key, the system runs the program that
executes the user’s command, and it outputs the results. The commands in UNIX are case sensitive, which
means that the system distinguishes between uppercase and lowercase letters. Most system commands are
typed in lowercase letters. A UNIX command consists of three parts: the command name, its options, and its
arguments. Options typically begin with a dash (−). The command name, options and arguments are separated
by spaces. Thus, e.g. to shutdown the system you should type:# shutdown –h 0
Here is the command format I shall use in this document:
OPTIONS A list of the most useful options and a brief description of each.
Getting Started 2
A UNIX Commands Reference Tutorial
UNIX Commands
Using the above command format, the first command we have learned, shutdown, is given:
ARGUMENTS time Shutdown the system after time secs or now (time=0).
Setting a password
If you were not assigned a password when your login account was set up, the system will probably request
that you choose one the first time you login. Passwords keep unauthorized users from using your account and
harm your files or others’ files. Once your password has been set, only you can access your account.
FORMAT passwd
Set or change your login password. The program prompts for the old
DESCRIPTION password (if any) and prompts twice for the new password.
OPTIONS None.
ARGUMENTS None.
EXAMPLE passwd
An alphabetical index of the most common UNIX (and LINUX) commands appears on the top frame of this
web page. For more information check the references (especially [1]).
References
Getting Started 3
A UNIX Commands Reference Tutorial
URL: http://jnkostaras.freeservers.com/index.html
Getting Started 4
−A−
COMMAND NAME alias
Create your own abbreviations (aliases) for commands. With no arguments it displays a list of all
DESCRIPTION aliases. To cancel the alias use unalias.
OPTIONS None.
The abbreviation we want to use, an equal sign, and the command to be abbreviated. If the command
ARGUMENTS contains spaces or other special characters (e.g \ ! *) use single quotes (' ').
COMMAND NAME at
DESCRIPTION Execute the command(s) read from the standard input or from a specified file at the time specified.
−ffilename Read the command(s) from the file specified (not from the standard input).
OPTIONS
−m Notify the user by mail when the job has completed.
at 08:00
EXAMPLE at> echo "It's 8 o'clock. Wake up!"
at> (Ctrl−D)
URL: http://jnkostaras.freeservers.com/a_unix.html
−A− 5
−B−
COMMAND NAME bc
FORMAT bc
EXAMPLE bc
FORMAT bg [ %n ]
Execute processes in the background. With no arguments it displays the jobs that
are currently executed in the background. If a number is provided, then the
DESCRIPTION process with the given number is executed in the background. One can also add
the & in the end of a command to make it processed in the background. See also
fg.
OPTIONS None.
bg %1 or %1 &
EXAMPLE
cp −r /usr/man . &
−B− 6
Creator: John N. Kostaras − email: [email protected] Last modification: 5 March 2000.
URL: http://jnkostaras.freeservers.com/b_unix.html.html
7
−C−
DESCRIPTION Display the calendar of the current month (with no arguments) or the month and/or year given.
OPTIONS None.
Display one or more files on your terminal screen. If more than one filename is supplied, it is
DESCRIPTION “concatenated” to (i.e. added in the end of) the previous file and displayed.
ARGUMENTS The filename(s) in the order that you want them to display.
COMMAND NAME cd
FORMAT cd [ pathname ]
DESCRIPTION Change current directory. With no arguments the command moves you to your home directory.
OPTIONS None.
The (full or relative) path name of the directory to which you want to move. (.) is the current
ARGUMENTS directory (..) is the parent directory.
EXAMPLE cd src
−C− 8
A UNIX Commands Reference Tutorial
OPTIONS None.
The name of the group whom you want to own the file(s) or directory(ies) and the name(s) of the
ARGUMENTS file(s) or directory(ies) you wish to change the group of.
OPTIONS None.
The octal number or a character representation of the new file access permissions
and the name(s) of the file(s) or directory(ies) whose file access permissions are
going to be changed. It consists of 3 parts:
Who Action License
ARGUMENTS
u user + Grant license. r read
g group − Do not grant license. w write
o other x execute
OPTIONS None.
The name of the user whom you want to own the file(s) or directory(ies) and the name(s) of the
ARGUMENTS file(s) or directory(ies) you wish to change the ownership of.
FORMAT clear
−C− 9
A UNIX Commands Reference Tutorial
DESCRIPTION Clear the display. After that only the prompt is displayed at the top left of the terminal.
OPTIONS None.
ARGUMENTS None.
EXAMPLE clear
OPTIONS None.
The names of the files to compare. If they are equal, returns nothing, otherwise it returns the first
ARGUMENTS char and line where the two files differ.
The name of the file you want to compress. The compressed file has a .Z
ARGUMENTS added to the end of the filename.
COMMAND NAME cp
−i Ask before updating a file or directory that exists in the destination with the same name.
OPTIONS
−r Copy recursively each subdirectory of the named directory too.
ARGUMENTS The name of the file you want to copy and the destination to where you want to copy it.
−C− 10
A UNIX Commands Reference Tutorial
URL: http://jnkostaras.freeservers.com/c_unix.html
−C− 11
−D−
COMMAND NAME date
FORMAT date
EXAMPLE date
COMMAND NAME df
FORMAT df [ −k ][ filesystem]
Display the amount of disk space used and available on the given filesystem in blocks (1 block =
DESCRIPTION 512 bytes or 1024 bytes). With no arguments displays the amount of disk space used and available
on all mounted filesystems.
EXAMPLE df /home
OPTIONS None.
COMMAND NAME du
−D− 12
A UNIX Commands Reference Tutorial
DESCRIPTION Display the amount of disk space used by the specified file(s) or directory(ies) in blocks (1 block =
512 bytes or 1024 bytes). With no arguments, the disk used from the current directory is displayed.
EXAMPLE du −k essay
URL: http://jnkostaras.freeservers.com/d_unix.html
−D− 13
−E−
COMMAND NAME echo
DESCRIPTION Display its arguments to the standard output. With no arguments an empty line is displayed.
OPTIONS None.
FORMAT exit
OPTIONS None.
ARGUMENTS None.
EXAMPLE exit
URL: http://jnkostaras.freeservers.com/e_unix.html
−E− 14
−F−
COMMAND_NAME fg
FORMAT fg [ %n ] or %n
OPTIONS None.
EXAMPLE fg %2
COMMAND_NAME find
Search the specified directorie(s) for files that satisfy the search−pattern and
act on them according to action(s).
Search−patterns:
−name filename: Search for files with the specified
filename.
− size n: Search for files of n blocks (usually 512 or 1024
bytes).
− links n: Search for files with n links.
− atime n: Search for files that have been last accessed
before n days.
− mtime n: Search for files that have been last modified
before n days.
DESCRIPTION − newer filename: Search for files that have been modified
more recently than the specified file.
Actions:
− print: Display the path(s) of the files found.
− exec command: Run for each file found; {} represents
the file specified.
− ok command: As the previous one, but it asks for your
approval before every action.
Note: Search−patterns can be combined.
! means negation;
− o means logical or;
one or more search−patterns are combined using logical and;
( ) or \ \ can be used to define groups of
search−patterns.
−F− 15
A UNIX Commands Reference Tutorial
OPTIONS None.
The search−path(s), the search−pattern and the action(s) to perform for each
ARGUMENTS file found.
URL: http://jnkostaras.freeservers.com/f_unix.html
−F− 16
−G−
COMMAND NAME grep
Search the specified file(s) for lines that contain the pattern and then display these lines. If more
DESCRIPTION than one files are given, the filename is displayed before the line(s). If no file(s) are given, the
standard input is searched.
URL: http://jnkostaras.freeservers.com/g_unix.html
−G− 17
−H−
COMMAND NAME head
Display the first n lines of the named file(s). If no option number is given then the first 10 lines are
DESCRIPTION displayed.
OPTIONS −n The number of the lines to display from the top of the file.
FORMAT hostname
OPTIONS None.
ARGUMENTS None.
EXAMPLE hostname
URL: http://jnkostaras.freeservers.com/h_unix.html
−H− 18
−I−
URL: http://jnkostaras.freeservers.com/i_unix.html
−I− 19
−J−
COMMAND NAME jobs
FORMAT jobs
OPTIONS None.
ARGUMENTS None.
EXAMPLE jobs
URL: http://jnkostaras.freeservers.com/j_unix.html
−J− 20
−K−
COMMAND NAME kill
ARGUMENTS The ID of the process you want to kill (returned from ps).
URL: http://jnkostaras.freeservers.com/k_unix.html
−K− 21
−L−
COMMAND NAME learn
FORMAT learn
OPTIONS None.
ARGUMENTS None.
EXAMPLE learn
Display printer queues' jobs. Displays information about the file(s) in the printer's queue; its owner
DESCRIPTION name, id, size and its filename. The filename displayed is the temporary filename in the printer's
queue and not the file's name.
OPTIONS −Pprinterqueue Specify the printer's queue instead of using the default.
ARGUMENTS None.
EXAMPLE lpq
Print the filename(s) to the line printer. Sends the filename(s) to the line printer's
DESCRIPTION queue. With no arguments, standard input is being printed (end with Ctrl−q).
−h Print no header.
OPTIONS
−Pprinterqueue Specify the printer's queue instead of using the default.
−L− 22
A UNIX Commands Reference Tutorial
Remove the file(s) with the information provided from the printer's queue. The file id and
DESCRIPTION filename are provided by lpq.
OPTIONS −Pprinterqueue Specify the printer's queue instead of using the default.
fileowner Removes from printer's queue all the files with the file owner provided.
ARGUMENTS fileid Remove from printer's queue the file with the file id provided.
filename Remove from printer's queue the file with the specified filename.
COMMAND_NAME ls
For each directory named, list its contents and any other information requested; for each filename,
DESCRIPTION list the requested information.
−L− 23
A UNIX Commands Reference Tutorial
A file name or a directory name. If no filename or directory name is given, the current directory is
ARGUMENTS listed.
EXAMPLE ls −Fal
URL: http://jnkostaras.freeservers.com/l_unix.html
−L− 24
−M−
COMMAND NAME man
ARGUMENTS The name of the command you want to find information for.
OPTIONS None.
EXAMPLE mesg n
OPTIONS None.
−M− 25
A UNIX Commands Reference Tutorial
OPTIONS None.
COMMAND NAME mv
OPTIONS None.
ARGUMENTS The name of the file or directory you wish to move and its destination.
URL: http://jnkostaras.freeservers.com/m_unix.html
−M− 26
−N−
URL: http://jnkostaras.freeservers.com/n_unix.html
−N− 27
−O−
URL: http://jnkostaras.freeservers.com/o_unix.html
−O− 28
−P−
COMMAND NAME passwd
FORMAT passwd
Set or change your login password.The program prompts for the old password (if any) and prompts
DESCRIPTION twice for the new password.
OPTIONS None.
ARGUMENTS None.
EXAMPLE passwd
COMMAND NAME pc
Compile Pascal source files (.p) or Pascal object files (−o). The
DESCRIPTION executable file that is produced is named a.out.
COMMAND NAME pg
FORMAT pg filename(s)
−P− 29
A UNIX Commands Reference Tutorial
OPTIONS None.
EXAMPLE pg foo
COMMAND NAME pr
Print the file(s) on the standard output, one page at a time. Each page consists of 66 lines with an
additional margin of 5 empty lines at the bottom of the page and a 5 line−header at the top. The
DESCRIPTION header consists of two empty lines, one line for the date, the filename and the page number, and two
more empty lines.
COMMAND NAME ps
FORMAT ps [ −aefx]
ARGUMENTS None.
EXAMPLE ps −ef
FORMAT pwd
Print the current working directory. Displays the complete path name of the directory you are
DESCRIPTION currently in.
OPTIONS None.
ARGUMENTS None.
−P− 30
A UNIX Commands Reference Tutorial
EXAMPLE pwd
URL: http://jnkostaras.freeservers.com/p_unix.html
−P− 31
−Q−
URL: http://jnkostaras.freeservers.com/q_unix.html
−Q− 32
−R−
COMMAND NAME rm, rmdir
URL: http://jnkostaras.freeservers.com/r_unix.html
−R− 33
−S−
COMMAND NAME set
Set a variable. With no arguments, display the values of all defined variables.
DESCRIPTION Dispose of the variable with unset.
OPTIONS None.
ARGUMENTS The name of the environment variable to set and its value.
ARGUMENTS time Shutdown the system after time secs or now (time=0).
−S− 34
A UNIX Commands Reference Tutorial
Sort the lines of the named file(s) together and write the result(s) to the standard output. Sort
DESCRIPTION standard input if no input files are given. Write the results to standard output if no output file is
given.
−d Use “dictionary” order. Only letters, digits and blanks are significant.−f Ignore case when
OPTIONS sorting.−n Sort numeric strings arithmetically.
−r Reverse sort.
Checks the spelling of the input file and lists the words that do not appear in its dictionary on the
DESCRIPTION standard output.
−S− 35
A UNIX Commands Reference Tutorial
URL: http://jnkostaras.freeservers.com/s_unix.html
−S− 36
−T−
COMMAND NAME tail
Display the last n lines of the named file(s). If no option number is given then the last 10 lines are
DESCRIPTION displayed.
+n The number of the lines to display starting from the beginning of the file.
−n The number of the lines to display from the bottom of the file (i.e. the last nth lines of the
OPTIONS
file).
lbc Determines the meaning of the number, i.e. either lines (l), blocks (b) or characters (c).
Communicate with another user. The command passes on what you type on
DESCRIPTION your terminal to the other user's terminal. To end the transmission type
Ctrl−c.
OPTIONS None.
ARGUMENTS The login name of the user you wish to talk with.
COMMAND_NAME tar
−T− 37
A UNIX Commands Reference Tutorial
The name of the backup (.tar) file and the filenames or directory names that are contained
ARGUMENTS in the tar file.
OPTIONS None.
COMMAND_NAME tty
FORMAT tty
Returns the path of the terminal the user is using. It returns something like:
DESCRIPTION /dev/tty08 meaning that the user is using terminal 8.
OPTIONS None.
ARGUMENTS None.
EXAMPLE tty
URL: http://jnkostaras.freeservers.com/t_unix.html
−T− 38
−U−
COMMAND NAME unalias
OPTIONS None.
OPTIONS None.
URL: http://jnkostaras.freeservers.com/u_unix.html
−U− 39
−V−
COMMAND_NAME vi
FORMAT vi [ filename(s) ]
DESCRIPTION Create or edit a text file with the given filename. If no filename is given, a new empty file is created.
The editor operates in two modes:
• command mode: allows the use of commands (it is in this mode when vi is started or
whenever the user presses Esc)
• text mode: allows text editing (to enter this mode use one of the commands a, i, o,
O, R or c).
r replaces character with the next character /template searches for the next appearance of the
you type template
R ovewrites previous characters, starting at ?template searches for the previous appearance
cursor position of the template
cw changes word with the next word you n repeats the last search command
type
commands for text movement
c) changes sentence
yy copies a line to the clipboard
−V− 40
A UNIX Commands Reference Tutorial
j joins the sentence of the cursor and the p pastes the text in the clipboard after cursor position
next sentence
P pastes the text in the clipboard before cursor
u undo last command position
OPTIONS None.
EXAMPLE vi newtextfile
URL: http://jnkostaras.freeservers.com/v_unix.html
−V− 41
−W−
COMMAND_NAME wc
Count the lines, words and characters of the named file(s). With no arguments the standard input is
DESCRIPTION used. If more than one filenames are given then it also calculates the sum of the lines, words and
characters of all files.
EXAMPLE wc −w essay
EXAMPLE who
COMMAND_NAME write
Communicate with a user by writing on their terminal. The requested user has to
DESCRIPTION
take explicit action to accept the conversation.
−W− 42
A UNIX Commands Reference Tutorial
URL: http://jnkostaras.freeservers.com/w_unix.html
−W− 43
−X−
URL: http://jnkostaras.freeservers.com/x_unix.html
−X− 44
−Y−
URL: http://jnkostaras.freeservers.com/y_unix.html
−Y− 45
−Z−
URL: http://jnkostaras.freeservers.com/z_unix.html
−Z− 46