Documentation
UNIX
Documentation table of contents.
Introduction
UNIX is a computer operating system which, over the years, has evolved into several major forms. The variant of UNIX available at the University at Buffalo is Sun Microsystems' Solaris OS. However, the information provided is general enough to apply to other versions of UNIX.
UNIX Layers
UNIX employs several layers in order to facilitate interaction between the computer hardware and the user. The first layer is the kernel, which runs on the actual machine hardware and manages all interaction with it. All applications and commands in UNIX interact with the kernel rather than the hardware itself. These applications and commands make up the second layer. The third layer is called the shell. The shell interprets commands, managing the interaction between the user, the applications, and the available UNIX commands.
A windowing system may be available on your OS, functioning as a fourth
layer between the computer hardware and the user. The windowing system usually
interacts with the shell, but can also interact directly with applications.
The final layer is the user. The user interacts with the entire operating
system through either the shell or a combination of the shell and the windowing
system. The figure below gives a visual representation of the layers of
UNIX:
Logging In
Note
Different domains require different accounts. You cannot log into an engineering machine with a UBUnix account, even though they may share a common UBITName (account name).
To log into UBUnix through one of the machines in a Public Computing Service Area, use a connection program such as PuTTY. Enter your UBITName and press Return or Enter. It is very important that you use lowercase letters for your UBITName, as the services used to authenticate logins are case-sensitive.
After you have entered your UBITName, the system will prompt you for a password. Enter your password and press Return or Enter.
Basic UNIX Elements
There are six basic elements of UNIX:
- Commands are the instructions given to the system. These instructions tell the system what to do.
- Files are named collections of data, and are stored in directories.
- Directories consist of several different files. A directory can also contain other directories. Directories, like files, are also named.
- The environment is a collection of items that describe or modify how the computing session will be carried out. It contains such items as the location of commands, the identity of the printer to which your output is sent, etc.
- Processes are commands or applications running on the system.
- Jobs are sequences of instructions given to the system from the time a particular task begins until the time it ends. A job may have one or more processes associated with it.
UNIX Commands
UNIX has a wide range of commands. These commands allow you to manipulate not only files and data, but the environment as well.
Basic Syntax
A UNIX command line consists of the name of the UNIX command followed by
its arguments. Arguments include command options, filenames, and other expressions.
You must press Return or Enter
to execute any UNIX command. The general syntax for a UNIX command is:
command [-flag options] file/expression
command indicates an action the system will take, flag and options modify the command actions, and file/expression is the name of the object on which the command acts.
The brackets around the flag and options are a shorthand way of indicating they are often optional, and should be invoked only if you wish to use a particular option. You may string together multiple flags, as well. Examples provided later in this document will illustrate this concept.
You should follow several rules when using UNIX commands:
- UNIX commands are case-sensitive, but most are lowercase.
- UNIX commands can only be entered at the shell prompt.
- UNIX command lines must end with pressing Return or Enter.
- UNIX options often begin with a - (a minus sign).
- Many commands can accept more than one option.
The man Command
Perhaps the most important command on the UNIX system is the
man command, which gives
you access to the standard online help facility available within UNIX: the
electronic reference manuals, known as the man pages. You can access these
pages by typing the following at your UNIX prompt:
man command-name
command-name is the name of the command for which you need help. The man pages provide an in-depth description of the chosen command, including an explanation of its options, examples, and further references.
If you are unsure of the exact command name you require, you can use the
-k option to search for a keyword
among the one line descriptions in the help files:
man -k keyword
You can read more about the man command by typing man man.
Other applications that reside on your system may have man pages. These pages can often be called up in the same manner as the man pages for the operating system.
Redirecting Input and Output
A number of conventions govern sources of input to a program or command,
as well as destinations of output from that program or command. The standard
input in UNIX is the keyboard, and the standard output is the screen. However,
UNIX is very flexible, allowing you to change or redirect the input source
and/or the output destination. For example, a command can be directed to
send the output to a file, rather than displaying the results on the screen.
This can be accomplished by using the output redirection symbol >:
command > outputfile
This command directs the system to store the output from command in the file named outputfile, rather than print it to your screen.
Each successive redirection to a particular file will overwrite all of
the previously existing data in that file. To append to the end of a file,
use >>:
command >> outputfile
Another redirection symbol is <, which tells the command to take its input from a file rather than from the keyboard. You may find that you have to type the same data a number of times in the debugging stage of program development. If you put the data in a file and direct the command to read it from that file, you only need to enter the data once while you make the data file.
The syntax for < is:
program < inputfile
inputfile, in this example, is the name of the file containing the data to be used by program. Using inputfile will give the same results as typing the data on the keyboard.
It is also possible to combine both kinds of redirections:
program < inputfile > outputfile
The data in the file inputfile will then be used as input for program, and all output will be stored in outputfile. If you want to store your output from multiple files in a single file, you can use >> to append output to the end of a file rather than replacing the previous contents, which > will do.
Note
Not all interactive programs accept input from a file.
The final input/output (I/O) redirection is the pipe symbol (|).
This command tells the computer to take the output created by the command
on the left of the pipe, and use that as the input for the command on the
right. An example of the pipe command is:
date | program
In this example, the output of the date command would serve as the input for program.
Special Keys and Control Characters
UNIX recognizes special keys and control character keystrokes, and assigns them special functions. You can invoke a control character keystroke such as Ctrl c by holding down the key labeled Ctrl and simultaneously pressing the c key. The notation for control characters is usually ^c or Ctrl c.
Some standard special keys and control characters are summarized below:
| Special Key | Description |
|---|---|
| Delete | Acts as an erase key. Pressing Delete once will back up and erase one character, allowing you to correct mistakes. |
| Backspace | Sometimes used to delete characters. Otherwise, it is mapped as a backspace key, which generates a ^H on the display. |
| Ctrl u | Erases the entire command line. It is also called the line kill character. |
| Ctrl w | Erases the last word on the command line. |
| Ctrl s | Stops the flow of output on the display. |
| Ctrl q | Resumes the flow of output stopped by Ctrl s. |
| Ctrl c | Interrupts a command or process in progress and returns to the command line. If this does not return you to your command line prompt, try typing the command several times in succession. |
| Ctrl z | Suspends a command or process in progress. |
| Ctrl d | Generates an end-of-file character. It can be used to terminate input to a program, or to end a shell session. |
Selected Command List
The next few tables summarize many of the basic UNIX commands you need in order to get started.
Setup and Status Commands
| Command | Description |
|---|---|
| logout | Ends your UNIX session. |
| stty | Sets terminal options. |
| date | Displays or sets the date. |
| finger | Displays information about users. |
| ps | Displays information about processes. |
| env | Displays or changes current environment settings. |
| set | Sets shell variables. |
| alias | Defines command abbreviations. |
| history | Displays recent commands. |
File and Directory Commands
| Command | Description |
|---|---|
| cat | Concatenates and displays file(s). |
| more | Paginator that allows you to browse through a text file. |
| less | More versatile paginator than the more command. |
| mv | Moves or renames files. |
| cp | Copies files. |
| rm | Removes files. |
| ls | Lists directory contents. |
| mkdir | Creates a directory. |
| rmdir | Removes a directory. |
| cd | Changes the working directory. |
| pwd | Displays the name of the present working directory. |
| du | Summarizes disk usage. |
| chmod | Changes mode (access permissions) for a file or directory. |
| file | Determines the type of a file. |
| quota -v | Displays current disk usage for this account. |
Editing Tools
| Command | Description |
|---|---|
| pico | Simple text editor. |
| emacs | Advanced text editor. |
| vi | Screen-oriented (visual) text editor. |
| grep | Searches a file for a pattern. |
| sort | Sorts and collates lines of one file. |
| diff | Shows differences between the contents of two files. |
Formatting and Printing Commands
| Command | Description |
|---|---|
| lpq | Views printer queue. |
| lpr | Sends file to printer for printing. |
| lprm | Removes job from printer spooling queue. |
| printers | Lists available printers. |
Program Controls, Pipes, and Filters
| Command | Description |
|---|---|
| Ctrl c | Cancels current process or command. |
| Ctrl d | Generates end-of-file character. |
| Ctrl s | Stops flow of output to screen. |
| Ctrl q | Resumes flow of output to screen. |
| Ctrl z | Suspends current process or command. |
| jobs | Generates a list of background jobs. |
| kill | Terminates a process. |
| & | Runs process in background (placed at end of a command, e.g., maker&). |
| > | Redirects output of a command to a file. |
| >> | Redirects and appends output of a command to the end of a file. |
| >& | Redirects standard output and standard error of a command to a file. |
| < | Redirects a file to the input of a command. |
| | | Pipes the output of one command into another. |
Other Tools and Applications
| Command | Description |
|---|---|
| pine | Electronic mail and USENET news program. |
| man | Displays UNIX help pages on the screen. |
Files and Directories
Information on the UNIX system is stored in files and directories. All files and directories are stored in the system in a hierarchical fashion. The system structure follows that of a top-down tree diagram. At the top, from which everything else branches, is the root directory, named / (a slash character). Below the root directory lies a set of major subdirectories, usually including bin, dev, etc, lib, pub, temp, and usr. Therefore, the bin directory, for example, is a subdirectory (or child) of /, and consequently / is the parent directory of bin. Each path leading down away from the root ends in a file or directory. Paths can branch out from directories, but not from files.
A large grouping of files and directories is known as a file system. File systems are related to the disk size, disk structure, and internal structure of UNIX. User files and directories are usually hosted on one file system, while system files and directories are hosted on another. If the number of users is large, the user files and directories may be hosted on more than one file system.
Creating Files
UNIX files can be of various types and can hold numerous types of data. Files are all independent and cannot be nested inside of each other.
Many UNIX files are created using a text editor. A text editor can manipulate saved text by allowing corrections, deletions, or insertions to a file. The main text editors on UBUnix are vi, Emacs, and pico. For more information on these editors, see the reference card for vi, and the CIT documents for Emacs and pico.
Displaying Files
You can display a file in one of several ways. For example, you could use the cat command:
cat filename
filename is the name of the file you would like to view. This will cause the text contained in filename to scroll very quickly down the screen. While it is possible to control the flow of text by using Ctrl s to stop the flow of text to the screen and Ctrl q to restart it, this can be very inconvenient. The more command displays one screen of information at a time before waiting for a keyboard prompt to continue:
more filename
The first page of text contained in filename will echo to your screen. You can press the Spacebar to advance through each page of text until you reach the end of the file. For help information on the more command, press ?.
A more powerful command called less is available on many systems. Among other enhancements, the less command allows you to scroll backwards through a file. The syntax for the less command is the same as that for more. For more information, type man less.
Listing Files
The ls command lists files in the current directory. The command uses many important flag options in order to obtain specifics about the files in the directory:
| Command | Description |
|---|---|
| ls -a | Lists all the contents of the current directory, including files with initial periods, which are not usually listed. |
| ls -l | Lists the contents of the current directory in long format, including file permissions, size, and date information. |
| ls -s | Lists the current directory's contents and file sizes (in kilobytes). |
If you have many files, your directory list might be longer than one screen. You can use the pipe symbol (|) in conjunction with the commands more or less to display the output from ls one page at a time:
ls | more
Copying Files
To make a copy of a file, use the cp command:
cp filename newfilename
filename is the file you wish to copy, and newfilename is the file you are creating.
It is possible to copy files to other directories without moving or changing the original file. The syntax for the cp command is very similar to that used for mv:
cp sample.txt ~/projects
The new file will have the same name as the old one unless you change it while copying it:
cp sample.txt ~/projects/newsample.txt
Naming Conventions
Each UNIX file has a filename unique to its current directory. As UNIX imposes very few restrictions on filenames, it is possible to name your files in such a way that the contents can be easily recognized. For instance, if your program calculates compound interest on an amount, you might call it interest. If your file is a research paper on Albert Einstein, you might call it einstein.
A filename can be up to 256 characters long, and may consist of any sequence of alphanumeric characters on the keyboard except the / symbol (the name of the root directory). Filenames may also include periods. In a file, the part after the period is known as an extension. Extensions usually indicate the type of information stored in the file. UNIX does not require extensions; however, they can be used to help identify similar types of files. You may use any extension desired: a text file might have the extension .txt or .text, a graphic image may have the extension .gif, and so forth. Some UNIX programs (especially compilers) look for certain standard extensions. Therefore, it is common practice to use the following notations:
| Extension | Description |
|---|---|
| .h | Header files |
| .c | C source files |
| .f | FORTRAN files |
| .s | Assembler source files |
| .txt | Text files |
For example, the file einstein.txt indicates a text file, whereas the file interest.c indicates a C++ program called interest.
Some UNIX files begin with a period. These files are called hidden files or initialization files. The .cshrc and .login files are good examples. These files will not appear in a normal directory listing. In general, they serve to set up UNIX environments and applications.
UNIX directories follow the same naming conventions as UNIX files.
Do not include blanks in your filenames, as they will make it difficult for you to work with a file. If you do wish to separate words in a filename, use an underscore (einstein_paper) or a hyphen (einstein-paper). Remember that UNIX is case-sensitive, which means that it recognizes the difference between uppercase and lowercase letters (e.g., einstein and EINSTEIN would refer to two different files).
Absolute and Relative Pathnames
Each directory and file on the system has a path by which it is accessed. This path is called a pathname. There are two types of pathnames. The first of these (the full or absolute pathname) traces the absolute position of the file or directory back to the root directory. The second (the partial or relative pathname) traces the position of a file or directory relative to the current directory (also called the present working directory, or pwd). Pathnames of both sorts use slashes (/) to show breaks between directories.
UNIX provides certain abbreviations for a few special directories. The tilde character (~) is shorthand for your home directory. The home directory of any user can thus be abbreviated from /parent-directories/userid to ~userid. Likewise, you can abbreviate /parent-directories/youruserid/file to ~/file. The current directory has the abbreviation . (a period). The parent of the current directory uses .. (two consecutive periods) as its abbreviation.
Permissions
It is important to protect your UNIX files and directories against accidental or intentional removal by yourself or other users. UNIX maintains permissions for every file and directory on the system. Permissions dictate which users do and do not have access to a particular file or directory.
Every file or directory in a UNIX file system has three types of permissions (or protections) that define whether certain actions can be carried out. The allowances made by the permissions change depending on whether the item is a file or directory. The three permissions are:
- read (r): A user who has read permissions for a file may look at its contents or make a copy of the
file. For a directory, read permission
enables a user to find out what files are in that directory.
- write (w): A user who has write permissions for a file can alter or remove the contents of that file.
For a directory, write permission
enables a user to create and delete files in that directory.
- execute (x): A user who has execute permissions for a file can execute the contents of that file (provided that it is an executable file, such as a program). For a directory, execute permission allows a user to change directories to that directory using the cd command which is discussed later.
For each file and directory, you must set the read, write, and execute permissions separately for each of the following classes of users:
- user (u): The user who owns the file or directory.
- group (g): Several users purposely lumped together so that they can
share access to each other's files. Groups are defined by the system administrator.
You can view those groups to which you belong by using the groups
command.
- other (o): The remainder of the authorized system users.
You can change permissions for any files or directories located on UB File Service (UBFS) directly with the UNIX command chmod from your ubunix (ubunix.buffalo.edu) account or from the web at https://ubfs.buffalo.edu/. This includes files in your public_html directory which are located in UBFS. Managing permissions from the web is described at ubit.buffalo.edu/ubfs/permissions.php.
The ls command
is the primary command for displaying information about files and directories.
The -l option will display the information
in long format. You can obtain information about a single UNIX file by typing
the following:
ls -l filename
Each file or subdirectory displayed by the ls -lg (long, groups) command consists of seven fields: permission mode, link count, owner name, group name, file size (in bytes), time (of last modification), and the filename. Each of these fields is discussed below.
The first 10 characters make up the mode field. If the first character is a d, then the item listed is a directory. If it is a dash (-), then the item is a file. If it is an l, then it is a link to another file. Characters 2-4 indicate the user permissions, characters 5-7 indicate the group permissions, and characters 8-10 detail the other permissions. If a particular permission is set, the appropriate letter appears in the corresponding position; otherwise, a dash indicates that the permission is not given.
The second field, the link count, indicates the number of links to the
file. In most cases it is one, but other users may make links to your files,
thus increasing the link count. The third field gives the owner's UBITName,
while the fourth reveals the group ID. The next two fields give the size
of the file (in bytes), and the date and time of the last modification to
the item. The last field gives the item's name. A typical display result
of the ls command looks like this:
-rw-r--r-- 1 owner abcdue 588 Jul 15 14:39 myfile
In this example, myfile has read permissions for every class of system user and write permission for the owner. Note that no one has execute permission for myfile.
The owner can change any or all of the permissions with the chmod (change mode) command. The arguments supplied to chmod are symbolic specifications of the changes required, followed by one or more filenames. Specifications consist of the following:
- The set of users for which permissions are to be changed: u for user, g for group, or o for others. You may also use some combination thereof, or a for all.
- The way in which the permissions should be changed: + to add a permission, - to remove a permission, and = to set the specified permissions while removing the current ones.
- The permissions to add or remove: r for read, w for write, and x for execute.
For example, to remove all the permissions from myfile,
you would type:
chmod a-rwx myfile
To allow read and write
permissions for all users:
chmod ugo+rw myfile
Finally, to allow only the read
permissions to all users:
chmod a=r myfile
There are certain advantages to allowing users only read permission. No one can execute or write to the file. Protecting a file against writing by its owner is a safeguard against accidental overwriting, although it is not a safeguard against accidental deletion.
As with files, directories have permissions associated with them. The following
is an example of permissions assigned to a directory:
drwxrwxr-x 1 owner abcdue 588 Jul 15 9:45 home
Anyone may read and execute the directory home and the files
and directories contained therein may be read and executed by anyone, but
only the owner and users in the group abcdue
may write to it. Assuming you are the owner of this directory, you may decide
to change the permissions to allow only yourself and members of the abcdue
group to read and execute files in the home directory. You would set the
permissions accordingly:
chmod o-rx home
If you decide that only you should be able to alter the contents of the
directory, then you must remove the write permission for the group:
chmod g-w home
Wildcard Characters
Wildcard characters allow you to copy, list, remove, and otherwise manipulate items with similar names. This is a great help in manipulating files and directories, although it should be noted that careless use of wildcard symbols may do more harm than good. UNIX supports the following wildcards:
- The symbol ? will match any single character in that position of the filename.
- ?ab2 would match any name that starts with a single character and ends with ab2, such as lab2 or tab2.
- ?ab? would match all the names that begin and end with a single character and have ab in between, such as labs or baby.
- The symbol * will match zero or more characters in that position in the file name.
- ab* would match all names that start with ab, including ab itself, able, or ability.
- a*b would match all names that start with a and end with b, including ab itself, alb, abb, or actiontab.
- Characters enclosed in left and right brackets, [ and ], will match any one of the given characters in the given position in the name.
- s[agz] would match sa, sg, and sz.
- s[2-7] would match s2, s3, s4, s5, s6, and s7.
These wildcard symbols help in dealing with groups of files, but you should remember that the command rm * would erase all files in the current directory (although by default you would be prompted to verify each deletion). Use the wildcard character * very carefully.
Removing Files
Note
It is very difficult -- and sometimes impossible -- to retrieve a removed file.
To delete files, use the rm command:
rm filename
To delete files with a confirmation prompt, use the -i option:
rm -i filename
Printing Files
To print a file from UBUnix to a specific printer, use the lpr command:
lpr [-Pprintername] filename
Pprintername is the name of the printer to which you want to print the file.
In the absence of a printername specified with the -P
option, lpr will print to the default
printer. If you have not set a default printer, then all printed files will
be sent to the printer located in 101 Bell Hall. To get a list of printers
available at your machine, type:
printers
This command echos to your screen a list of all named printers on the system, along with their types and locations. To get status information for the printers, use the command prstat.
Directory Structure
Note
On large systems, the usr directory may contain other bin, temp, and lib directories.
UNIX directories are similar to regular files, as both have names and contain information. Unlike files, however, directories contain other files and directories. Many of the same rules and commands that apply to files also apply to directories.
Many UNIX directories have traditional names and traditional content that do not vary from system to system.
| Directory | Description |
|---|---|
| bin | Contains binary files, which are executable command and application files. |
| lib | Contains library files, which are collections of routines that a compiler can include in a program. |
| dev | Contains device files, which are the software components of terminals, printers, disks, etc. |
| temp | Stores temporary files created by certain programs. |
| etc | Stores miscellaneous administrative files and commands. |
| pub | Contains public files (files that anyone can use). |
| usr | Reserved for user directories. |
Creating Directories
To create a new directory, use the mkdir
command:
mkdir directory
directory is the name of the directory you wish to create. The mkdir command will create a subdirectory beneath the current directory if a relative pathname is given. It will create a subdirectory in a different location if an absolute pathname is specified.
Displaying Directories
When you initially log into the system, UNIX places you in your home directory.
The pwd
command will display the full pathname of the current directory:
/home/userid
By typing ls
-a, you can see every file and directory in the current directory,
as long as you have read permissions on the directory. To display the contents
of your home directory when it is not your current directory, enter the
ls command followed by the full
pathname of your home directory:
ls /home/userid
Instead of typing the full pathname for your directory, you can also use
the tilde symbol (~) with the ls
command to display the contents of your home directory:
ls ~
To help you distinguish between files and directories in a listing, the ls command has a -F option. This option appends to each object in the directory a distinguishing mark that shows the kind of data it contains: no mark for regular files, / for directories, @ for links, and * for executable programs.
Changing Directories
To change your current directory to another directory in the directory
tree, use the cd command in any
of the following manners:
cd directory (relative pathname from home
directory)
cd ~/directory (full pathname using ~)
cd /home/userid/directory (full pathname)
To return to the parent directory of projects, you can use the special
.. directory abbreviation:
cd ..
If you become lost navigating directories, you can issue the cd command without any arguments. This will place you in your home directory. It is equivalent to typing cd ~.
Moving Files Between Directories and Renaming Files
The mv command is responsible for both moving and renaming files in UNIX.
To move a file into another directory by using the mv command:
mv filename directory
For example, the following command moves the file sample.txt into the projects directory:
mv sample.txt ~/projects
Since the mv command is capable of overwriting files, it would be prudent to use the -i option (confirmation prompt).
You can also move a file into another directory and rename it at the same time by specifying the new name after the directory path:
mv sample.txt ~/projects/newsample.txt
To rename one of your files, you can also use the mv command to "move" a file over itself. Change your present working directory to the directory storing the file you would like to rename and type:
mv oldfilename newfilename
where oldfilename is the name of the file you wish to move, and newfilename is the name of the new file.
Copying and Renaming Directories
To make a copy of a directory and its contents, use the cp command:
cp -R oldDirectory newDirectory
oldDirectory is the directory you wish to copy, and newDirectory is the directory you are creating.
To rename one of your directories, use the mv command as follows:
mv oldDirectory newDirectory
oldDirectory is the name of the file you wish to move, and newDirectory is the name of the new directory or location.
Whether you are copying a directory or renaming it, the new directory name must not be in existence prior to the execution of the command. The new directory need not be in the current directory; you can copy and move a directory anywhere within a file system, just as you can move and copy files.
Creating Links Between Files
It is possible to create links in different directories that point back to one particular file. The ln command creates this link. Note that links are simply alternative names for a single file. The ln command neither renames nor copies the file.
Because only one copy of the file actually exists, any changes that you make to the file will be reflected when you access it through another of its links. If you delete the link, however, you will not delete the file to which it points.
Links are useful for cross-referencing files. This method allows multiple users to access the file from several different directories, providing each user with access to up-to-date information whenever the original is altered. This method is also more convenient than using the file's absolute pathname every time you need to access it.
One type of link is the symbolic or soft link. Symbolic links refer to another file by its pathname. Symbolic links can refer to files on another system, to itself, or even to files that do not exist. Unlike a hard link, symbolic links point to another entry somewhere else in the file system. In addition to individual files, symbolic links may also refer to directories.
To create a symbolic link to a file within the same directory, type:
ln -s originalFile linkName
originalFile is the file to which you want to link, and linkName is the link to that file.
To create a link in a directory other than that of the original file, type:
ln -s originalFile differentDirectoryName/linkName
If you create a link within the same directory as the original file, you cannot give it the same name as the original file. There are no restrictions on a file's additional names outside of its own directory. Links do not change anything about a file. If a link is made to a file, and that file is deleted, the link will be rendered ineffective.
Removing Directories
To remove a directory, make sure that you are in that directory's parent directory, and then type:
rmdir directory
directory is the name of the directory you wish to delete. The directory cannot be removed unless all files and subdirectories contained in it have been erased. This prevents you from accidentally erasing important subdirectories.
You can erase all of the files in a directory by first going to that directory (using cd), and then using rm to remove the files. The quickest way to remove a directory and all of its files and subdirectories (and their contents) is to use the rm -r (recursive) command along with the directory's name. For example, to empty and remove your projects directory, move to that directory, then type:
rm -r projects
If you want to use the rmdir command so that it does not remove the contents of the directory without permission, use the -i option to receive a confirmation prompt prior to each directory deletion:
rmdir -i projects
Processes and Jobs
A process is a command or program running on the UNIX operating system. A sequence of related processes is called a job. Your applications, your programs -- even your shell itself -- are all processes. The UNIX kernel manages these processes on the system, usually without distinguishing among them. Because UNIX is a multi-tasking system, you can run one or more jobs in the background (unseen by the user) while continuing to work on another process in the foreground (seen on the user's screen).
Viewing Your Processes
The ps command shows you the status of your processes:
| PID | TT | STAT | TIME | COMMAND |
| 4804 | P3 | S | 0:00 | -sh (csh) |
| 1352 | p3 | R | 0:00 | ps |
| 3874 | p7 | IW | 0:25 | xclock -g 90x90-0+0 |
| 3875 | p7 | S | 0:48 | xbiff -g 90x90-95+0 |
The ps command displays the process ID (PID); the control terminal (TT); the process state (STAT); the CPU time used by the process so far, including both user and system time (TIME); and finally, an indication of the command that is running the process (COMMAND).
Background Jobs
If you put a program into an unattended state in which it continues to execute, you have placed it in the background. Running a program on one machine and displaying its output on another via a windowing system like X-Windows or CDE is not considered backgrounding the job.
You can run a job in the background by adding an
& (an ampersand) to the end of the command:
jobname &
You will receive a response like this:
[1] 5432
This response informs the user of three things: first, that there is one job running in the background; second, that its job number is 1; and third, that its process identification number (PID) is 5432.
Managing Processes and Jobs
The PID can be used to abort (kill) a job. To kill the job in the above
example, you would use the kill
command:
kill 5432
You could also use kill %1 to kill the process by its job number, as indicated by the number in brackets.
You can also use the job number to switch a job between foreground and
background. To switch a job from the foreground to the background, press
Ctrl z to suspend the job and then
use the bg (background) command:
bg %jobnumber
jobnumber is the number of the
job you wish to switch to the background. To switch a job from the background
to the foreground, use the fg
(foreground) command:
fg %jobnumber
jobnumber is the number of the job you wish to bring to the foreground. The jobs command will display a list of jobs and job numbers running in the background.
Logging Out
To end a work session, you must explicitly log out of UNIX by typing logout at the command prompt. Once you have logged out, you will no longer be connected to the system.
If you experience difficulty logging out, it may be because of several common problems. If the system replies to your logout command with There are suspended jobs, type jobs to see the jobs that are running under your UserID, type kill %% to terminate all stopped background jobs, then try logging out again.
If the system replies Not in login shell, typing exit and pressing Return or Enter should place you back in your login shell. After that, type logout at the prompt, if necessary.
Note
You should never turn a Sun workstation off; this will not necessarily log you out.
If you have tried these methods and still cannot log out, you might be stuck in a program or shell other than the login shell. Press Return or Enter to clear any previous commands, then try typing Ctrl c, q, :q, :q!, exit, Ctrl d, Ctrl q, or Ctrl z to get back into the login shell. After this, try the logout command again.

