Moving Around in the Dark

Everything is a File

One of Unix's original contributions to computing was the design choice to treat everything as an unstructured stream of bytes; what on Unix is called a "file". This means that all the input and output from the previous commands can be thought of as "files"! One consequence of this philosophy is that file extensions have no meaning to the computer, rather they are a hint to the user. On Microsoft Windows, executable programs end with a .exe or .com, but on Unix style systems programs have no extension at all (otherwise you would have to type ls.exe everytime you wanted to run a program). As we explore the file system, keep in mind that everything is a file.

Filesystem Hierachy

Linux Filesystem Hierarchy StandardOn the previous page we used the pwd program to print the working directory. Just like in a graphical file system browser, at any time the user has a current directory. Rather than double clicking a folder to enter it, use the cd command to change directories and the ls program to look around.
# cd /
# ls
# cd /bin
# ls
# cd /usr/lib
# ls

The filesystem has a specific hierarchy and set of common folders. Every directory is contained in the filesystem's root directory: /. Do not confuse this with the root user's home folder: /root. Rather than a "back" button, in the shell the .. directory refers to the current directories parent directory. If you display all contents of a directory (ls -a) you will always see the . (current) and .. (parent) directories. Go back a directory by using cd ..

# cd /usr/bin
# cd ..
# pwd
# cd ..
# pwd

The last line should have shown you are in the / (or root) directory.

Looking Inside Files

Now that you can move around the and see what's in different directories, let's learn a command that's often used to see what is in files: cat.

# cd /etc
# cat legal
# cat timezone
# cat environment

The /etc folder contains system configuration files. In a Unix and Linux, configuration of the system is handled through plain, flat text files. The last file is especially important because it contains the definition of an environment variable, the important PATH variable. Specifically, PATH is the environment variable that lists out the directories that the shell will look in for the program name invoked by a command. You can view shell environment variables using the echo command and typing a $ symbol before an environment variable name.

# echo $PATH
# echo $HOME
# echo $SHELL

You can view a full list of active environment variables with the env command.

Last modified: Tuesday, 16 June 2020, 2:36 AM