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. You can also download the tutorial in .pdf format by right clicking on the Adobe icon on the toolbar on the left and selecting "Save Target As ..." in the pop-up menu of IE or "Save link as ..." in Netscape Navigator and Opera.

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: john
Password:
 
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.
The OS will display the login: prompt, indicating that it is ready to accept a new login name.

Shutting down the system

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:
 
COMMAND NAME command name
FORMAT command [option(s)] argument(s)
DESCRIPTION A brief description of what the command does.
OPTIONS A list of the most useful options and a brief description of each.
ARGUMENTS Mandatory or optional arguments.
EXAMPLE A simple example of how to use the command.

UNIX Commands

Using the above command format, the first command we have learned, shutdown, is given:
 
COMMAND NAME shutdown
FORMAT shutdown [-g|h|r] time|now
DESCRIPTION Shutdown or reboot the system in a safe way.
OPTIONS -g|h   Shutdown and halt the system.
-r     Reboot the system after shutdown.
ARGUMENTS time        Shutdown the system after time secs or now (time=0).
EXAMPLE shutdown –h now

 

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.

 
 
COMMAND NAME passwd
FORMAT passwd
DESCRIPTION
Set or change your login password. The program prompts for the old password 
(if any) and prompts twice for the new password.
OPTIONS None.
ARGUMENTS None.
EXAMPLE passwd

Index of UNIX commands

 
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
  1. INTERACTIVE UNIX Operating System Primer – Version 3.0.
  2. Kernighan B.W., Pike R., The UNIX Programming Environment, Prentice-Hall: 1984.
  3. Waite M., Martin D., Prata S., UNIX Primer Plus, 2nd edition, The Waite Group: 1990.
  4. Libadas K., Papageorgas L., UNIX, Christodoulidis: 1988. (in Greek).

Creator: John N. Kostaras - email: jnkostaras@mail.gr
Last modification: 19 November 2001.
URL: http://jnkostaras.freeservers.com/index.html