Sie sind auf Seite 1von 6

AAGSD 2002

Unix Primer
Notation of examples in this guide
UNIX PRIMER
Commands that are typed in by you appear in boldface font. Additional input such as filenames, etc, appear in italic type. A carriage return, or the Enter or Return key, is used to send the command to the computer but is not specifically written here. Output including the system prompt from the computer will appear in regular font. For example: >ls
file1 file2 file3

>cat filename.txt The > is the system prompt displayed by the computer and indicates that the computer is ready for input. ls and cat are commands and the list of files returned by the computer, and filename.txt would be a filename specified by the user.

NOTE! Case is important!


In unix the case of the letters you type is very important. MAIL'will not be translated into mail''. A search for Word'in a document will only find occurrences of Word'where the Wis capitalized and the ord'is in small letters.

NOTE! You cannot undo a file deletion!


Unlike other operating systems, unix does not have a trash from which to recover a file.

Getting help
Finding online documentation:
apropos or man -f'can be used to find documentation for commands. The manuals are online. It is used as follows: > apropos more The keyword, more, can be replaced with any command for which you want more information. apropos will list all command documents that contain the word more.
Unix Primer

page 1 of 6

AAGSD 2002 The command associated with the key word will be listed with a brief explanation of the command. The above command gives a list including the following:
... more page destroy foreach lrange ... more (1) more (1) destroy (n) foreach (n) lrange (n) browse or page through a text file browse or page through a text file Destroy one or more windows Iterate over all elements in one or more lists Return one or more adjacent elements from a list

Accessing the documentation for a command:


man'is used to display documentation for a command. Use as follows: > man command The documentation is formatted to display clearly.

Directories
Viewing Your Current Directory:
To see what directory you are currently in, use pwd''. The output from this command is also the path to your current directory. Unix uses a hierarchical directory structure, so the path displayed starts with the top directory of the disk partition and contains all the directories down to your current directory. Note: The current directory is abbreviated as . and the directory directly one up is abbreviated as ...

Creating Directories:
To create a new directory in your current directory, use > mkdir newdirectory where newdirectory is the name of the new directory. You can also create a directory by specifying the complete path of the directory. For example, if your present directory was /home/yourusername, you could create directory by using the following: > mkdir /home/yourusername/newdirectory

Unix Primer

page 2 of 6

AAGSD 2002 Note: a directory must exist before you can create a directory under it.

Changing directories:
>cd is used to change directories. To move up one directory, use cd .. To move down one directory, use cd subdirectory. To move to a new directory tree or any directory, you can use the complete path of the directory. cd /home/yourusername/subdirectory1/subdirectory2 or cd ../directoryabove/directory are examples. To return to your home directory from any directory, use cd alone. Your directory can also be abbreviated by ~/.

Removing directories:
To remove an EMPTY directory, use rmdir dirname'where dirname is the name of the directory.

Files
The wildcard character * can be used with the following commands. It can replace one or more letters in a filename to select multiple files. For example, ro* will match rock, road, root. ro*t will only match root in the previous list. To match a single letter, use ?, for example, r?t will match rot but not root.

Listing files within a directory:


>ls lists all the files in your current directory. >ls directory will list the files in the specified directory. >ls l will list details about the files, including the file size. For other options of ls; use man ls to see the options available. >file filename will tell you the file type. This means whether the file is a data file, a directory, a file of shell commands, an executable, etc.

Displaying the contents of a file:


more is used to display the contents of a text file.

Unix Primer

page 3 of 6

AAGSD 2002 >more filename more displays a window or page at one time. Pressing the Return key, will display the next line line. Pressing the Spacebar, will display the next page. To exit the more display, type in q. The more display will automatically quit after all the documentation has been displayed. less is used to display the contents of a text file as well but allows scrolling. >less filename less displays a window or page at one time. Pressing the key and the , will navigate through the text. To exit the less display, type in q. The less display will NOT automatically quit after all the documentation has been displayed.

cat' can also be used to display the contents of files. cat dumps the complete file quickly to the screen. >cat filename To display the contents at the beginning or end of a file, use
>head filename >tail filename

,respectively. You can control the number of lines displayed by adding the desried number of lines to the command in this manner: >head 100 or >tail 50, where 100 or 50 lines will be displayed, respectively.

Using text editors to create files:


There are many editors available on unix. vi is an editor available on all unix machines but is not user-friendly. emacs or xemacs is an easier editor to use as it has drop-down menus.

Removing files:
rm is the command used to remove files.

Unix Primer

page 4 of 6

AAGSD 2002 Note: When combining wildcards with rm it is wise to use ls to first see what files will be selected. For example, if you want to delete all files ending with .txt: >ls *.txt file1.txt file2.txt

>rm *.txt In this way, you can see what files will be deleted before committing to the action.

NOTE! You cannot undo a file deletion!

Moving files:
mv is the command to move a file to a new directory or to RENAME a file. To move a file from your current directory to another directory, use > mv filename dirpath where dirpath is the directory path that file is to moved to. To move a file from some directory to your current one, use >mv /dirpath/filename . To rename a file simply move it to a new filename. >mv oldfilename newfilename

Copying files:
cp is the command used to copy files. To move a file from your current directory to another directory: >cp filename1 /dirpath/filename2

Finding files:
which can be used to find the location of a command For example to see where the more command is: >which more

Unix Primer

page 5 of 6

AAGSD 2002 /usr/bin/more To find other file types, use the find command as follows: >find /startdirectory -name filename -print where startdirectory is the name of the top directory from which you want to descend to make the search, and filename is the file for which you are searching.

Printing files:
lp can be used to print a file to the default printer. >lp filename

Unix Primer

page 6 of 6

Das könnte Ihnen auch gefallen