Introduction
In this lab, we'll explore the pwd command in Linux, a fundamental tool for navigating your digital workspace. Imagine you're a detective in a vast library of information, and pwd is your trusty compass, always ready to tell you exactly where you are. Whether you're a beginner just starting your Linux journey or looking to solidify your understanding, this lab will equip you with the skills to confidently navigate the Linux file system.
Understanding Your Starting Point
Let's begin our exploration by understanding where we are in the file system. The pwd command, short for "print working directory," is your first tool in this journey.
Open your terminal. You'll see a prompt waiting for your command. This prompt typically ends with a
$sign.
Type the following command and press Enter:
pwdYou should see output similar to this:
/home/labex/project
This output tells you that you're currently in the project folder, which is inside the labex user's home directory. This is what we call an absolute path - it starts from the root directory (/) and shows the full route to your current location.
What's happening here?
Think of the Linux file system as a tree. The / at the beginning represents the root of this tree. Each subsequent name separated by / is a branch or folder. So, /home/labex/project means you're in the project folder, which is inside labex, which is inside home, which is directly under the root.
If you're wondering why you started in the project folder, it's because the LabEx environment is set up this way for convenience. In a typical Linux system, you might start in your home directory (/home/username).
Exploring Your Current Directory
Now that we know where we are, let's take a closer look at our current directory.
We're going to use the
lscommand to list the contents of our current directory. Type:lsYou might see some files or directories listed. If the directory is empty, you won't see any output. That's perfectly normal!
Now, let's use
pwdagain to remind ourselves where we are:pwdYou should see the same output as before:
/home/labex/project
This step helps you understand that pwd always shows your current location, regardless of what files or directories are in that location.
Exploring pwd Options
The pwd command has a couple of options that become useful when your current directory involves a symbolic link. In this step, you'll move into the symbolic link created during setup so you can see the difference directly.
Note: A symbolic link is like a shortcut to another directory. You do not need to master symbolic links yet. Focus on comparing the paths shown by each
pwdcommand.
Move into the symbolic link directory:
cd /home/labex/project/symlink_dirUse
pwdwithout any options:pwdYou should see:
/home/labex/project/symlink_dirNow use the
-Loption to show the logical path:pwd -LYou should see the same symbolic link path:
/home/labex/project/symlink_dirFinally, use the
-Poption to show the physical path on disk:pwd -PThis time, you should see the real directory that the symbolic link points to:
/home/labex/project/real_dir
Here, pwd and pwd -L both keep the symbolic link name in the result, while pwd -P resolves the link and shows the actual directory.
The key difference between the two options is:
-L(logical): Shows the path you used to reach the current directory, keeping symbolic link names in the result-P(physical): Shows the actual directory on disk after resolving symbolic links
The important takeaway is that these commands can show different results when your current working directory includes a symbolic link.
Summary
In this lab, we've explored the pwd command, your trusty navigator in the Linux file system. We've learned how to:
- Use
pwdto identify our current location in the file system. - Understand the concept of absolute paths.
- Use
pwdin conjunction with other commands likels. - Explore the
-Land-Poptions of thepwdcommand and understand their differences when dealing with symbolic links.
These skills will serve as a foundation as you continue your Linux journey, helping you always know where you are in your digital workspace.



