Working With DirectoriesIncluded on this page:
- Directory Names
- Make a Directory
- List the Contents of a Directory
- Change the Name of a Directory
- Delete a Directory
- Navigating Directories
- Determine Your Current Directory
- Directory Abbreviations
- Move From One Directory to Another
You will probably find that you eventually will accumulate dozens (or even hundreds!) of files. Grouping them into different directories makes them easy to keep track of. For example, a directory named Receipts might contain monthly receipt figures with files named jan, feb, and mar. You may want to create directories and add new files to them, or delete existing files or directories you no longer need.
Your home directory is assigned to you when your account is created. Whenever you log in to your account, your session begins in your home directory. Your home directory is named with your userid name, the name you use to log in. You control your home directory--you can set permissions that determine who can read, change, and execute your files. You also determine the structure of your home directory--you can create any other directories, or files you want within your home directory.
Figure 1: A Home Directory With Files and Directories
This will make a directory with the name you specify
To make a directory for your chemistry papers and
This makes the directory named Chemistry. If you begin your directory names with a capital letter, they are easier to distinguish from your file names.
To view the names of the files and directories in a different directory, enter:
The ls command takes several command options that let you display additional file and directory information. The following list summarizes some of the most popular options:
ls -l Displays files in long format (see File and Directory Permissions and Access)
ls -t Displays sorted by time of last modification
ls -r Displays in reverse order
ls -F Displays contents and indicates file type
You can also use the ls command with several options at once:
ls -lFt directory
mv directory1 directory2
This changes the name of directory1 to directory2.Delete a File).
To delete a directory, enter:
To display the name of your current directory, enter:
For a user with the userid "jjaudubon," who is working in their home directory, the pwd command display would look something like this:
Figure 2: A Unix Directory Structure
Absolute PathnameIn the Unix file system, the uppermost directory is known as the root directory (see Figure 2). All other directories are located under the root directory. An absolute pathname starts with a slash (/) to represent the root directory, then traces a path through the file system to a specific file or directory. You can specify any file or directory in the file system by means of its absolute pathname.
Because the absolute pathname starts at the root directory, it always begins with a /. All the names in a pathname are also separated by a /. Do not be confused by the dual meaning of the / character. It is both the symbol of the root directory and a separator between names. In the Unix file system, it is possible for more than one user to have a file called jan. Two files with the same name, for example jan in Figure 2, are distinguished by their absolute pathnames:
Relative PathnameA relative pathname shows the route to any file or directory from your current directory.
Both User1 and User2 can access their files named jan from their home directories using relative pathnames:
|~||Your home directory|
|..||Parent directory-the directory just above your current directory|
To copy a file from your home directory to your
current directory, enter:
cp ~/file .
This command uses the abbreviations for your home directory (~) and your current directory (.) to copy the file you specify.
To move to another directory, enter:
This moves you from your current directory to the directory you specify.
To move to your home directory from anywhere in the file system, enter: