Filesystem and Paths

One of the main uses of a computer is storing and retrieving data. While the data itself is just stored as zeros and ones, the filesystem is how this information is organized so that is easier for you and software to find. In terms that are antiquated now, each chunk of information is called a file, files can be grouped in a directory (also called a folder) and the filesystem refers to the overall structure of all the folders and directories. A file can be of many different types; a music file, an image, a video, code, or a text file. Any information stored on a computer is a type of file. Many files have an extension, usually the last 2 to 4 letters after a period that indicate what type of file it is. Some examples, .doc, .pdf, .mp3, .mp4, .jpg, .gif, .log, .txt, .mov, .xlsx, .gz. Note that these extensions are meant to be helpful, they don’t change the file type, and aren’t needed, though some programs will have difficulty reading a file without the right extension.

You may not have noticed the filesystem while using your computer because many programs are setup to store and read files from certain locations. So your photos, videos and music are probably all stored in places that the programs you use to access those things know where to find them.

GUI Interface

You also have probably used a GUI interface to the filesystem. For Windows 10 this is called File Explorer (previously Windows Explorer) and on Mac OS X this is called Finder. In both cases the GUI allows one to see files, navigate directories and open files with the appropriate software. The filesystem tree can be somewhat obscured by these interfaces.

Command Line Interface

One can also navigate the filesystem from the command line. On a Unix/Mac OS X system the key commands are ls, cd, and pwd (For Windows they would be CD and DIR). These will list the contents of a directory, change a directory and give the location of the present directory. For example:
$pwd
/Users/ari/Desktop
$ls
budget.txt me.jpg
$cd ..
$pwd
/Users/ari

Typing pwd, returns the current directory I happen to be in which is the Desktop directory which is under the ari directory which is under Users. The / has a special meaning on Unix systems as the end of a directory. The highest level of the directory tree is staring with a /. The ls command returns the names of all files in my Desktop directory which turns out to be just two, budget.txt and me.jpg. Then to move around in the filesystem one uses the cd command, cd followed by a directory name like Desktop will move you into the Desktop directory. To move up one directory one can use the cd .. command.

Paths

Generally one only has access to files if one is in the same directory as the file. For example, open me.jpg will work if I’m in the directory Desktop, but anywhere else it will give the error message The file /Users/ari/me.jpg does not exist. One can get around this by giving the path to the file. For example, if I was in the directory /Users/ari then open Desktop/me.jpg would work. This is called a relative path, because it works relative to where I currently am. One can also give the absolute path open /Users/ari/Desktop/me.jpg which would work from any directory on my computer.

Paths can be set up in programs and the users shell so that certain directories are checked for files. For example, you’ll notice that cd isn’t a file on my Desktop, so how did the OS know what to do when I type cd. We can find the path to cd using the which command (WHERE on Windows).
$which cd
/usr/bin/cd

so we see that cd can be found in the bin directory under usr. So how did cd run when I typed it? My shell is configured to search in /usr/bin when it gets a command. We can see this by looking at the directories in my environmental path
$printenv PATH
/Users/ari/anaconda3/bin:/Users/ari/anaconda3/condabin:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

which returns eight directories separated by colons of which one is /usr/bin.

Print this page