UNIX Primer

Home | Primer Home


The Filesystem

Files need to be organized in a manner that makes them easy to find. In UNIX-based systems, this is accomplished by organizing files into a 'tree' structure. In this tree, there is a 'root,' which is a directory that contains every other directory on the system. This root directory contains other directories, which are 'branches' of the tree. Those 'branches' may contain other 'branches.' In this manner, we can move throughout the tree freely by moving up and down branches. We cannot move lower than the root. We cannot move higher in a directory with no more directories in it.

There is also the notion of a 'current directory' in which each user resides. For instance, when you first log on, you are in your 'home' directory. You can use 'ls' to see all the files in your directory, or type 'pwd' to see the full name of your 'home.' You can move to a directory in your home or to your home's 'parent directory' using the 'cd' command. A directory's 'parent' is the directory that most directly contains it. For instance, if you type 'pwd' again, you will see lots of directory names separated by '/' characters. Each of these describes a 'branch' taken away from the root, in order. The last one is your 'present working directory' and the one right before it is the 'parent' of that directory, and the one before that is its parent, etc, until you hit the root. The root has no parent directory.

In our filesystem, the root has a name. Its name is '/'. This is a special name given to the root of the filesystem to make it easy for us to navigate. There are many of these 'special' filenames. They are:

/   - the root directory
~   - your home directory
.   - current directory
..  - parent of current directory

Try playing with the 'pwd' 'cd' and 'ls' commands to get a feel for the filesystem. You cannot hurt anything by using these commands, so roam freely throughout the filesystem and get used to how we navigate. Also, now that you can see which files are there, you can use 'cat' 'more' and 'less' (lesson 3) to view them, and you can create directories within your home directory using 'mkdir' (lesson 4). If you get lost, you can enter 'cd ~' or 'cd' to return to your home directory.

Related Commands:

NameMeaningPurpose
pwd Print Working Directory Prints the name of your current working directory.
Syntax
pwd
Notes
  • This command always shows the 'absolute path' of your current directory. See the next lesson for more about absolute paths.

NameMeaningPurpose
ls LiSt Lists filenames.
Syntax
ls (filename)
ls -l (filename)
ls -a (filename)
Notes
  • Filename is optional
  • -l option lists detailed file information
  • -a option forces ls to list all files (normally, it omits files that begin with the '.' character
  • Options can be combined - see the man page for more options.

NameMeaningPurpose
cd Change Directory Changes your current working directory.
Syntax
cd <filename>
Notes
  • The special filenames described above are very useful with this command. Entering 'cd ..' moves you one directory closer to the root.
  • Entring 'cd' without a filename or 'cd ~' should return you to your home directory.

See Also:


Designed by D. Kaminsky
Edited by Diana Palsetia
© University of Pennsylvania, 2008