Unix Filesystem Overview

Written by Chris Gregg, with modifications by Nick Troccoli

Click here for a walkthrough video.

The unix file system is simply a tree, with the root of the tree labeled "/" (forward slash). Files and directories (also called "folders") make up the nodes of the tree, and directories can contain more files and directories.

For example, you may have a directory on your computer called "CS107", which has some files and directories in that directory. If you run the tree command, you will get a list of the files and directories in a tree format:

$ tree cs107 -F
cs107
├── 
│   ├── main*
│   ├── main.c
│   ├── main.cpp~
│   └── readme.txt
├── assign1/
│   ├── file1.txt
│   ├── file2.txt
│   ├── folder1/
│   │   └── myProgram.c
│   └── folder2/
└── assign2/
    ├── docs/
    └── readme.txt

6 directories, 8 files

(Note: in the above listing, names that end with / are directories, names that end with * are executable - runnable - files)

When you log into the myth computers, you are assigned a home directory, which looks something like this: /afs/.ir/users/c/g/cgregg.

You have access to read, write, and delete files inside your home directory, but you can't read another person's directory unless you have permission.

For CS107, you will have read access to a number of class-related directories, but you won't be able to modify the files in those directories. Instead, often we will ask you to copy the files into a directory you will create inside your own home directory.

Your home directory is also known as ~ (tilde), and you can refer to your home directory simply by the tilde character.

There are two special files for every directory, called . and ..

. refers to the current directory. This makes it easy to refer to your current directory instead of typing a long line such as /afs/.ir/users/c/g/cgregg/107/assign0. If you are already in that directory, you simply use . to refer to that directory. We often use the single dot to enable us to run a file that is in the current directory, since in general you must specify exactly where your programs are that you would like to run. So, if you were in the assign0 directory and had a program called hello that simply prints out hi there in that directory, you would use the following command to run it:

$ ./hello

Note this means that that cd . (cd is the "change directories" command) will not change directories and will keep you where you are.

The double-dot (..) directory refers to the parent of the current directory.

You use unix filesystem commands like cd and ls to navigate and explore your way around. See the other unix command references on the resources page for more information.