Sunday, August 8, 2010

How to organize large collections of files

What is a directory?

  • In a Unix file system, a directory is basically a place where files live, that is, sort of a container for files.
  • When you type the ls command, it shows you the files that are in your current working directory, but there are many other directories.
  • A directory can contain files, but it can also contain other directories.
  • Directories in a Unix file system are organized into a hierarchy, starting at the root directory.
  • When you refer to a file in a command, that file is assumed to be in the current directory.
  • You can refer to a file in some other directory by using its pathname.

Before we discuss pathnames, let's first look at the overall organization of Unix file systems.

Changing your current working directory


At any given time, you are located in some current working directory within the Unix file tree. When you log in, your current directory is set to your home directory.

You can change your current working directory any time by using the cd command (this stands for "change directory"). For example, if the current directory has a subdirectory named details, you can change to that directory using the command:

    % cd details

You can always find out the absolute pathname of the current working directory by typing the command:

    % pwd

Assuming you are using csh as your shell, you can always return to your home directory by typing:

    % cd ~

What is a pathname?


You can refer to any file in any directory on the system by using its Linkpathname. A pathname is a string of characters that describes what directory the file is in, as well as the name of the file.

The pathname of a file in the current working directory is just the name of the file by itself. For example, when you first log in, the current working directory is your home directory. If you create a file called foo in that directory, you can refer to it simply as foo.

Files that are in a different directory than the current working directory can be referred to by three different methods:

  1. An absolute pathname describes another directory in a way that does not depend on where you are.
  2. A relative pathname describes some other directory's relocation relative to the current working directory.

No comments:

Post a Comment