The file system of UNIX is like a tree spreading from the root to the leaves. The root directory is indicated by "/", and the system and users directories are organized under the root directory. When logging in, the user normally enters his Home directory directly. The user can create subdirectories under his Home directory. Table B-2 shows the directory browse and control commands commonly in use:
Table B-2 Commands for directory browse and control
Command/Syntax Function
pwd Display current working directory
cd [Directory] Switch directory
mkdir Directory Create a directory
rmdir Directory Delete a directory
ls [Option] [Directory or File] List directory content or file information
I. Display current working directory -- pwd [Description]
The command "pwd" is used to locate the current direcory at any time.
[Command format] pwd
[Example]
Display current working directory:
$pwd
/export/home/sybase
Caution:
Unlike DOS, UNIX does not always display the directory name, therefore it is necessary to execute the command "pwd" from time to time to display the current working directory.
II. Switch directory -- cd [Description]
The command cd is used to switch to another directory from the current directory. It can handle both absolute path and relative path.
[Command format] cd [Directory] [Example]
Return to Home directory:
$ cd
$ cd /
Go up one directory:
$ cd ..
Go up two directories:
$ cd /
Enter directory /export/home/sybase by absolute path:
$ cd /export/home/sybase
Note:
After a user logs into the system and switches to other working directory, how can he return to the Home directory promptly?
The command "cd" without any parameter, as shown in below, can server the purpose. $ cd
III. Create a directory -- mkdir [Description]
The command "mkdir" is used to create a subdirectory. When determining the path of the newly created directory, both absolute path and relative path can be used.
[Command format] mkdir directory [Example]
Create a subdirectory "data" in direcory "/home1/omc":
$ mkdir/home1/omc/data
If the current directory is "/home1/omc", the above command can be simplified as :
$ mkdir data
IV. Delete directory [Description]
When the command "rmdir" is used to delete a directory, the directory shall be empty. Otherwise, the files in that directory shall be deleted first. What’s more, to delete the current working directory, the user must first "jump" up to the upper level directory.
[Command format] rmdir directory [Example]
Delete the subdirectory "data" in directory "/home1/omc":
$ rmdir/home1/omc/data
If the current directory is "/home1/omc", the above command can be simplified as:
$ rmdir data
V. List directory content -- ls [Description]
The command "ls" is used to list the files and subdirectories in the selected direcory. Executing the command "ls" without any parameter will list the content of current directory. Executing the command with parameters will list information about the size, type, authority of the file and the date when it was created and modified.
[Command format]
ls [Option] [Directoy or File]
[Description of options]
There are many options for the command "ls" and combination of options can be used -- but remember to put a prefix "-" before the options. Here are some common options: -a List all the files, including the hidden files (files starting with a dot, such as
".login").
-F Specify the type of the file by suffix signs. The meanig of the suffixes are: / directory file
= pipe file @ sign-linking file * executable file
-l List the detailed information about a file, including the file type, authority, number of links, owner, file group, file size, filename and the date of last modifications, etc. If the file is a sign-linking file, there will be a sign "->" at the end of the filename, pointing to the linked file.
[Example]
Display the long-form content of the files in the current directory:
$ ls -l |more total 11094632
drwxr-xr-x 2 sybase staff 1024 Sep 5 2001 bin
-rw-r--r-- 1 sybase staff 2048000000 Mar 6 09:50 data_dev.dat drwxr-xr-x 2 sybase staff 512 Sep 5 2001 devlib
Note:
z When the command "ls –l" is executed, the files displayed may take up several screens. Two ways are
available to display the files one screen at a time:
z ls -la | more
z ls -la>ccc Save the result to file "ccc", then execute the command "$ more ccc", the result will be
displayed one screen at a time.
z When the command "ls -l" is executed, seven columns of information will be displayed. z There are 10 characters in the 1st column:
z The first character indicates the file type (e.g. "-" stands for a common file and "d" for directory, etc). z The following nine characters are three triplets indicating the access authority of the file owner. The
first triplet pertains to the owner, the middle triplet pertains to members of the user group and the rightmost pertains to everyone else in the system ("r", "w" and "x" indicate that the user has the authority to read, write and execute the file, while "-" indicates that the user has no related authority for it).
z The 2nd column indicates the number of hard links of the file.
z The 3rd and the 4th column display such information as the owner of the file, and the user group to
which the file belongs.
z The 5th column shows the size of the file in byte.
z The 6th column shows the time and date when the file is last modified. z The 7th column shows the filename.