UNIX File Systems - The File System and Important Directories
(Page 3 of 5 )
The directory is also a file, even though it only contains directory entries. If you want to find out what files and directories are under it, you just have to open it and view its entries. The File System comprises the hierarchically-ordered files and directories. At the root of everything is the root directory.
The root directory is represented by a single / character. Beyond this, like a tree, are the files and the directories. Every directory has two special directories. One, represented by a single point, points at the directory itself, while a second, represented by two points, refers to the directory above. In the case of the root directory, of course, these are missing.
In case someone uses it, note that it will point back to the root directory (i.e. /bin, ../bin/ and ../../bin will point to the same directory). Below the root directory, the files are sorted into categories, so you can easily find what you're searching for. This is subject to change depending upon your UNIX/Linux distribution; however, mainly this is the way distributions work.
/boot => The kernel and the files required for the start of programs
/home => The users own directory
/dev => The devices
/tmp => The temporary files
/var => Files that expand
/bin => The binary files
/sbin => Binaries that only the super user can execute
/proc => The kernel maintains this and it contains information about the processes
/usr => Important files used by the system and the user
For example /usr/lib the libraries
/usr/include the C header files
/usr/bin Files that can run
/usr/src The source files
When we work with files, there are two important directories. One is the current working directory; the one that is used by the shell to put work into. The second one is the home directory of the user. This can be replaced with the ~ character. Therefore, the ~/alfa will refer to the alfa file/directory of my home directory. Of course, if my work directory is the home one, I can also refer to alfa with just a simple alfa.
This relative place of files based on where our current work directory is allows us to make a difference between the absolute and relative path to a file. The absolute path is the completely explicit route, while the relative path is based on where I am. Whatever the case is, the route is just a sequence of characters separated by the character /.
There is a command that will extract from a path the name of the file, and another one that will extract the route to the file. The first is entitled basename while the second is called dirname. The following examples will illustrate how they work.
basename /home/gaborj/alfa.cpp
With the result of:
alfa.cpp
dirname /home/gaborj/alfa.cpp
With the echo of:
/home/gaborj
Note that giving an extension to files in UNIX is not required. Still, it is recommended to further help us separate and categorize our files.
Next: Working with Directories and Files >>
More Miscellaneous Articles
More By Gabor Bernat