Chapter 2. Basic Unix Commands

Table of Contents

Online Documentation. The Unix Manual
A Tour of the File System
Conventions
File Manipulation
Directory Manipulation
Security
Communicating with Users
Programming
Manipulating Text Files

This document gives a very brief overview of the basic Unix commands. Please refer to a book or the online documentation for more information. Don't be afraid to experiment with a command to figure out what it does. There is a fair amount of variation from one Unix system to another. Experimentation is usually the best way to understand how your system works.

[Warning]Warning

Many Unix commands will do nasty things without asking for confirmation. Thus if you have no idea what a command does, you should read about the command first. This simple practice will save you a lot of grief. Don't trust Unix utilities to ask first. They don't.

Online Documentation. The Unix Manual

The Unix manual is, of course, available in printed form. In fact, you can buy it at a good computer bookstore. It's rather large—many volumes. Most Unix systems have the manual online. You can access it via the man command. For example, if you want to read the manual page on the cp command, type

$ man cp

at the prompt (the '$' above represents the prompt; your prompt might look different). Typically the man command will automatically pipe the output through the more filter for easy reading. If you want to keep a manual page around to read later, try redirecting the output of man to a file.

$ man cp >cp.man

The Unix manual comes in roughly eight sections, although the precise number depends somewhat on which Unix system you are using. Here is what is covered in each section.

Table 2.1. Unix Manual Sections

Section #1The utility programs (ls, ps, cc, sh, ...) Unix comes with many utility programs from those that do basic file manipulation to those that support serious program and document development.
Section #2The system calls (a C library). This section documents the Unix API as seen by a C programmer. Functions like open, chmod, setuid, etc are here.
Section #3The C library. This section documents all the functions available to a C programmer that are not true system calls. Functions like fopen, strlen, isalpha, etc are here.
Section #4Information on "special files"
Section #5Information on the file formats. By consulting this section, you can write your own programs that manipulate the various system files. This section also typically contains tutorial information.
Section #6The rules for the games that are on the system.
Section #7"Miscellaneous Useful Information Files." For example, information on nroff macros might be found here.
Section #8System management commands and procedures. Section one contains information about management commands that are of interest to the general user (actually called section 1M). This section pertains to commands that either cannot be executed by the general user or that would be useless to the general user.

The man command lets up look things up in any section. For example

$ man fopen

gives you information on the C library fopen function.

In some cases a name appears in more than one manual section. For example if you do

$ man chmod

you get information on the chmod utility program from section 1. If you want information on the chmod system call, you must do

$ man 2 chmod

since the system calls are in section 2.

Unix manual pages have a standard format. Many third-party programs use the same format for their documentation. You will get used to it once you've looked at enough manual pages.