Whenever the user logs into the system, a home directory is associated with the user's login name. Most of the user's files and subdirectories are located in this directory. It is useful to group files that are similar into a subdirectory. This makes it easier to find files.
For example, Programs/C/prog1.c is a file that is found in a subdirectory. To find this file you would type:
% cd Programs/C
Now the file prog1.c is located in the current directory. To go up one directory, (Programs) you type:
% cd ..
The user can do 5 things to access their directories:
1. Changing to another directory as the working directory cd (See above)
2. Determining which directory is the working directory pwd
3. Listing the contents of a directory ls
4. Creating new subdirectories: mkdir
5. Removing an existing directory rmdir
1. The command cd directory_name changes the directory you wish to go to.
2. The command pwd shows the full path name of the working directory. After changing directories you can type pwd to make sure you are in the correct directory.
3. The command ls lists the contents of the directory. (See below)
4. To create a new directory use the command mkdir directory_name.
5. The command to remove a directory is rmdir directory_name.
To list all the files in the directory use the command ls.
There are several options that can be used with ls:
Option Function -l long form -a all entries -r lists in reverse order -t lists by time last revised
% ls -la
total 24
drwxrwxr-x 6 smith users 766 Feb 28 19:32 . drwxrwxr-x 8 smith users 290 Mar 15 9:25 .. -rw-r--r-- 2 smith users 320 Jan 17 15:39 book -rw------- 5 smith users 425 Apr 23 10:07 hw drwxr-xr-x 1 smith users 512 Jun 29 17:21 public_html
The first line (total 24) shows the amount of disk space used, measured in blocks. Blocks are 512 characters each in most older Unix systems. The next set of characters which are either letters or hyphens, identify who is able to access the file.
In the line given for each file, the first character in each line (d, -, b or c) tells you the type of file.
d = directory - = ordinary disk file b = block special file c = character special file
The next nine characters make up three groups of three and describe the permissions for the file or directory. The first 3 are for the owner, the second 3 are for group, and the last 3 are for public.
More information about accessing or changing permissions can be found on the next page.
The next number is the link count. "For a file, this is equal to the number of users linked to that file. For a directory, this number shows the number of directories immediately under it plus two (including the directory itself and its parent directory." (Fortgang 61)
Next, the login name of the file's owner is listed (smith), followed by the group name of the file or directory (users). The following number tells you the length of the file or directory entry measured in bytes. The month, day and time the file was last modified is listed next. The last column shows the name of the directory or file.
The command mv (short for move) lets you rename a file in the same directory or to move a file from one directory to another. Once you move a file to a different directory, the file can be renamed.
To rename a file in the same directory you can type:
mv file1 file2
For example:
%mv index index.html
%ls
index.html
hello.c
%
To check to see if the file index.html exists type ls as shown in the example.
A file can also be moved from one directory to another. To move the file without changing its name type:
mv file directory
The file and directory names can be any valid names, including path names.
For example, if you want to move the file apple from the current directory fruit (whose full path name is /home/smith/fruit) to a file with the same name in the directory misc (whose relative path name from fruit is ../misc and whose full path name is /home/smith/misc). You can use any of the following command lines:
mv apple /home/smith/misc
mv apple /home/smith/misc/apple
mv apple ../misc
mv apple ../misc/apple
mv /home/smith/fruit /apple /home/smith/misc/apple
If you want to rename the file apple to apples when moving it to the directory misc, you can type any of the following:
mv apple /home/smith/misc/apples
mv apple ../misc/apples
mv /home/smith/fruit/apples
mv /home/smith/misc/apples
You can check to see if the file was renamed by using ls.
To remove a file from your directory you can use the command rm (short for remove).
The basic format for rm is:
rm file
You can remove more than one file at a time by listing the files you want to delete on the command line with a space between each file name:
rm file1 file2 file3
Once a file is removed, it is removed permanently.