The Unix File System

Directories

Directories contain files or other directories. The ``visible'' part of your account is your home directory and the subdirectories of your home directory that you, or applications that you use, create.

Your home directory is part of a fairly large directory tree which contains all user accounts, system files, and output devices.

The following commands are useful when working with directories from the Unix shell (which is usually the most efficient mode of operation):

pwd
Display current location in the directory tree.
cd directory
Change current directory. Change to home directory if no argument given.
mkdir directory
Create a new directory with the given name.
rmdir directory
Remove directory with the given name. If the directory is not empty, use rm -r instead, but make sure you know what you are deleting!

The directory argument is usually the name of a directory, but can also be one of the following abbreviations:

~
Home directory.
~xy
Home directory of the user named xy.
.
Current directory.
..
Parent directory of current directory.

Listing Files

ls
List files in current directory. Files starting with . (``dotfiles'') will not be listed.
ls -a
List all files in the current directory.
ls -l
Long list.

The long list gives file permissions (see below), number of hardlinks, owner, group, file size, modification time, and file name. The information about file permissions is very important. The format is

A dash indicates that a permission is not set. The first column entry can be one of the following:

-
Regular file.
d
File is a directory.
l
File is a soft link to another location.
c
Device file that does char I/O. (There are more device types.)

The file permissions can be changed with chmod, for example chmod u+x filename sets the execute permission for the user (i.e., for you), or chmod o-r filename revokes the read permission for other users not part of the ``group'' (for all practical purposes you should treat ``other'' and ``group'' alike). Directories must be executable!

Moving Files Around

mv source target
If target is a directory, move the source into target. Otherwise rename source into target.
rm
Delete the given file(s). There is no way to un-delete files! To delete a directory and all of its contents, use rm -r. If you don't want to be prompted for every file, use rm -f or rm -rf respectively.
cp
Copy a file, usage similar to mv.

File Name Abbreviations

Archiving and Compressing files

For transmission or long term storage, it is useful to combine several files into one, and/or to compress a file. This is done by using the tar and gzip commands.

Manual Pages

man command
Displays the ``manual page'' for command.
apropos keyword
Displays a list of commands that have to do with keyword.

Pipes, redirection, greping

> <
redirection of stdout or stdin
|
``piping'' output of one process into another
grep
looks for a string in a file or files.

Examples:

grep alias .cshrc
searches for string ``alias'' in the file .cshrc
ls -l | grep dr
gives a list of directories
grep John *
looks for ``John'' in all files of current directory
ps -ef | sort
gives a sorted list of processes running on your machine.



Last modified: 1998/02/20
Marcel Oliver (oliver@math.uci.edu)
The index for ``Using Unix in the CAMLAB'' can be found at http://www.math.uci.edu/~moliver/unix/index.html.