Introduction

Introduction

A directory is a special kind of file that is used to arrange other files into groups. For example, in writing this book, I have created a directory Linux into which I'm placing the files associated with each chapter:

Directories are arranged under the root directory, "/", in a structure called the directory hierarchy, or directory tree (see Figure 5-1 for a diagram of a simple directory tree).

Figure 5-1. Sample Directory Tree

graphics/05fig01.gif

The internal construction of directories is similar to that of files in most ways. Directories have owners and groups associated with them. They have permissions associated with their owner, group, and the rest of the world. (See the chmod command in Chapter 2 for a bit more information about permissions.) They have access times, modification times, and change times, all stored within the inode. The biggest difference between files and directories is that where the inode of a file contains pointers to data blocks, the inode of a directory contains pointers to other files.

Directories are pervasive, so there is a substantial collection of specialized jargon associated with them. The following are some of the highlights:

home directory: A user's home directory is the directory where he or she is placed at login. Home directories for a given user are defined in that user's entry in the /etc/passwd file. Because it is so common to need to specify files relative to your home directory, a specialized symbol has been defined for each user's home directory: The tilde, "~", can be used in shell commands to indicate your home directory. In the following examples, assume that we're still talking about my home directory, /home/shawkins:

Abbreviation

Equivalent to

Example

~

/home/shawkins

cd ~

~/linux

/home/shawkins/linux

cd ~/linux

current directory: Whenever you're logged in, you have a current working directory, your current location in the directory tree. This is the output of the pwd command. When you enter the command ls -a, the current directory shows up with a filename of ".". The shell variable for your current directory is $PWD. To change your current directory, use the cd command.

graphics/tip.gif

I get sick of typing pwd all the time, so I set up my bash shell prompt to display my current working directory. It works pretty well, except when I get more than four or five levels deep in the directory tree. At that point the shell prompt starts cutting seriously into my typing space. If you're interested in trying this out for yourself, add the following line to your ~/.bashrc file:

 

export PS1='$PWD> '

You'll have to re-source your .bashrc file, either by logging out and then back in or by entering

. ./.bashrc

before the new command prompt will take effect. (Note: "PS1" is the shell variable for your command line prompt.)

parent directory: For any given directory, the directory above it in the directory tree. The parent directory also has a shorthand symbol, "..", which can be used in commands. For example, say your current working directory is /home/shawkins/linux. If you enter the command,

cd ..

your new current working directory will be /home/shawkins.

subdirectory: Any directory below another in the directory tree. /home/shawkins is a subdirectory of /home, and /home/shawkins/linux is a subdirectory of /home/shawkins.

The commands covered in this section include

cd

Change directories.

mkdir

Create a new directory.

pwd

Print the current working directory.

rmdir

Remove the specified directory.

symlinks

Find symbolic links.

 



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net