The File System and pwd (Print Working Directory)

File System and Directories

GET THE FULL COURSE HERE

The directories and their sub-directories of your file system make up a hierarchy. We saw an introduction to this hierarchy when we discussed that the user folders are within a folder called /Users or /home.

As you code, you will navigate your shell prompt to different folders on your hard drive.

We’ll need to take a small deviation to learn about the important abbreviations for any Unix system to understand how it works.

Whenever you specify a file path— a location to file or a group of files or folders — the first character or two characters is important. Always notice how a file path begins. The very first character (or characters) tell you where the file is: at the root, in a specific folder, or in a parent folder above the current folder.

These four symbols are ., .., ~, and /

If there is no special character, it is as if you used the single dot . specials character.

The meanings of the Special First Characters When Referring to Filepaths on Your System

./ or no first special character
(except when used in a filename)
single dotsthe current directory I am in (or the current working directory)
../two dotsis the parent directory, that is, the directory above this one
~/tildehome directory
/forward slashroot of my hard drive

These characters are the basis for how you will reference all paths in Unix, and we will use this information throughout this course. The next two lessons will also review this to show you real-world examples of how these are used. For now, be sure to commit to memorizing these four special signifiers.

Using a single dot is just like having no dot at all (a relative path that is relative from the current working directory). However, note that there is an exception to this rule when a single dot appears as the start of a filename. In that case, it refers to the filename, and is not a relative path specifier.

The single dot tell unix that you mean: “relative from my current working directory, go find me this thing.”

Typically, when navigating in Unix, you can leave it off and trust the shell prompt will interpret your input as relative to the current directory (hence why it is called the “relative path”).

The first characters of how you specify your pathname determines how the system will interpret what you say. If you begin it with a single dot . you mean “from the current directory.” If you begin your path with two dots .. you are saying “from the parent directory.”

If you begin with a tilde character ~ you are referring to a path in your home directory.

Your home directory is typically set up for you by the operating system. On my Mac, for example, my home directory is in /Users/jason . When I write ~ in a filename that means /Users/jason (on your system, it will mean your home directory. On Mac systems, this begins with /Users. On other systems, it typically begins with /home but can be anywhere)

If you begin your filepath with / (on the shell prompt) that means the root of your hard drive.

Don’t confuse Single Dots in Filepaths with Invisible File Dots

As we discussed in the previous lesson,

When you see a ./ at the beginning of a file path, you know it means “the current directory” or whatever directory you are currently in. Don’t confuse that with a dot that begins a filename or folder name that is invisible.

You can recognize one from the other because the “current directory” single dot will come before a slash, indicating “the current directory.” Otherwise, it will be part of the filename itself.

Remember, you can typically leave off the “single dot” to mean the current directory, so most of the time, you don’t need it.

The Working Directory & pwd

Where you currently are at your shell prompt— that is, the current directory— is called the current working directory (or CWD).

Let’s start with your first Unix command: pwd

pwd stands for print working directory and will do just that. It will print the location where you are at your shell prompt, also known as the current working directory.

To run pwd, simply type pwd at the command prompt and see what happens.