Select Page

Paths and Directories – pwd

pwd (print working directory): To know where you’re currently working in your terminal

When working in a terminal, you need to jump over different folders to perform different tasks. Sometimes you might get lost as your terminal may or may not show where you’re currently working. In that case, pwd command will show you your working path and folder.

up1 1

This command will make sense in the next lesson. And you’re ready to skip to the next lesson. But here, if curious, you’ll deep dive into the concepts of paths and directories.

Path vs Directory

A directory is a folder, where you store files or other folders. A path is an address to a folder. It shows you how you can get to a folder. In the above picture, Coursera is a folder or directory in my file system. But how can I get to that folder? I need to open Home folder, then fahim folder, Desktop folder, Programming folder, finally the Coursera folder. This entire direction or address is called Path.

Absolute Path vs Relative Path

Paths can be of 2 types depending on how they are presented. If you remember from Know Your Terminal lesson, a file system starts from root, which is denoted by ‘/’. From there, you can navigate to any directory you want. So, a path that starts from the root and goes to your working folder is called Absolute Path. Therefore, absolute paths start with ‘/’. An absolute path to the Desktop folder in my PC looks like this:

/home/fahim/Desktop

Note: The ‘/’ syntax is used at the beginning of a path to indicate the top-level directory, which is root. It is also used to separate the names of directories in a path in Linux. Windows uses backslash ‘\’ to to this job. Your URLs also use forward slash ‘/’.

If a path starts from any other directory and goes to your working directory, then it’s called Relative Path. When you first open your terminal, you see the path is presented by ~ (tilde), which stands for Home directory. So you by default open your terminal in a relative path. To see the absolute path, run:

$ pwd # exclude the dollar sign and the space

Paths can be relative to your current working directory. Your current working directory is denoted by a single dot (.), and the directory immediately above it is denoted by double dots (..). So relative paths may also start with single or double dots. Read the next lesson for detailed examples.

up2 1 1
Absolute path ‘/home/fahim’, relative path ‘~’

Understanding Linux /home directory

Your PC can have multiple users. All users should have different chunks of file system, but they all are stored inside the same folder, called /home. As ‘/’ denotes the root, ‘/home’ is actually a folder under the root. Here’s how this looks on my PC.

up3 2
Notice the home and root folders, and the top that show the directory ‘/’

Don’t get confused by the root folder under ‘/’, we’ll discuss it in a moment. All the users in my PC will have different folders under the Home folder. One user can’t access another’s folder, while a root user can access any folder. Everone’s personal folder is called his/her home directory. So my home directory should be /home/fahim. A user continuously has to visit his/her home directory, that’s why a shortcut to the home directory is denoted by ~ (tilde). So when you open a terminal, you’re at your home directory. You can, however, change your home directory to any other folder. Say I want my home directory at:

/home/fahim/programming/python

In that case, ~ will represent this entire directory. Keep in mind, each user’s home directory contains his terminal properties, command history file, application settings etc. So one user’s settings and preferences won’t collide with others.

So, to jump back to your home directory from any other directory, just use any of the commands (details in next lesson):

$ cd ~
# or
$ cd

Understanding /root directory

This is the home directory for root user, or admin user, or superior user. Don’t get confused between ‘/’ and ‘/root’. They represent different purpose. Notice the image above, which shows the ‘/’ directory in my PC. There’s also a root folder.

‘/’ is the main folder where your file system resides. It’s the starting of the file system. We call it root, to represent the very first folder in the file system. Then there is root user, think of it as admin. It’s a user. But instead of storing it inside the Home folder, it has it’s own independent home directory. So, /root is the home directory for root or admin user.

Why the home directory of the root user is a different folder? Because of security reasons. Remember, a root user has every permission, so s/he can do whatever s/he wants.

Mind Sharing It?
Join Facebook Group

Public Group

A group optimized for learning purposes. Track your progress by joining a unit

Follow on Quora

Public Space

Best place to ask questions! Join the built-in community to get help from others