*nix File Systems
(a newbie’s guide)

This is a guide for newbies on how to get around a *nix-based file system.

Let’s start with how the file system works (in laymen terms). A file is line of bytes (or an array of bytes if you will). It starts at one point and doesn’t brake until the end of the file. See the diagram below.

Code:
[]-----------------------|FILE|------------------[]
[]-----|This_If_A_File|-|FILE|-----------|FILE|--[]
[]--|FILE|-------|Another_File|------------------[]
A file can be written starting at any point in the file (not just the beginning). The file system does not distinguish records/structure in the file, it’s up to the program to know what to do with the data. A good example would be a database record, or like how ASCII Character #13 means new line in text files. A File name can be up to 255 characters long (in most current file systems that I’m familiar with). The file also stores a “Pointer” to it’s position on the hard drive- along with permissions and ownership.

Directories or Folders are also files. They store a list of files and other folders contained there in. Each line of the file represents a file in the directory, containing the files name and it’s location. There is no limit to the amount of folders that can be stored with in folders within folders. The first folder in this tree of data is called the “root” directory, or sometimes known as “/”. See the diagram below.
Code:
/
|
|---/tmp
|
|---/usr
|   |
|   |---/bin
|
|---/home
When you (or a program) want to access a file, you must specify it’s Path (example: “/user/bin/passwd.conf”). This path must include 0 or more folders, separated by slashes.

If the path begins with “/” that means it’s going to start in the “root” directory. If the path does not begin with a “/” then it starts looking in the current directory.

A process (or program) can set the root and current directories, this is done using the “chdir” and “chroot” system calls. Although only programs running under elevated privileges can set the root dir.
Now, for some commands:

1.) “ls” - list directory contents
2.) “cd” – change current directory

Context:

“cd /” This would bring you to the root directory.
“ls” Lists all the files in the current folder.

When using “ls” I like to add the “-F” switch. This will display all folders with “/” to let you know they are folders. This makes things a little less confusing. “ls –F”

Another great command is “man”. This stands for MANual, the manual is a set of “manual” files, which are essentially helps files, there should be a “manual” page for each application on your machine. For example; if I wanted to know a little more about the “ls” command, I would type “man ls”- displaying the “man” page for the ls binary.

Now that we know how to view and locate files on the system, where should we look? Here I will try to list some key directories and the files they contain (for the most part). [“/”] I don’t like to keep files here, but that’s just me [“/bin”] Stands for Binary, this is where most of the system binaries are kept, programs like ‘ls’ ‘man’… [“/etc”] this is where many programs store their configuration data. [“/lib”] OS and Programming Libraries. [“/tmp”] Stands for Temporary, files that are usually discarded… These are certainly not all the directories on your machine, I recommend that you take a look for your self sometime.

And, that’s it. You should be able to run around a *nix file-system like a pro If you don’t have *nix on your machine, you can always obtain a shell account, this is a great way to test/learn *nix… This guide is by no means intended to be a full/complete reference of any sort. If you’d like to know more, hit up your favorite search engine!