Identify Your Home Directory with pwd and cd
In this step, you will learn two fundamental commands for navigating the Linux filesystem: pwd and cd. We'll start by identifying your current working directory and then learn how to move to your home directory.
The pwd (print working directory) command tells you your current location in the filesystem's hierarchy. When you start a new terminal session in this lab, you are placed in a specific directory called project. Let's verify this.
Execute the pwd command in your terminal:
pwd
You should see the following output, which is the absolute path to your current directory:
/home/labex/project
Next, let's explore the cd (change directory) command. This command allows you to move between directories. Every user on a Linux system has a special "home" directory, which is the default location for storing personal files. For your user, labex, the home directory is located at /home/labex.
A convenient shortcut to navigate directly to your home directory from anywhere in the filesystem is to type cd without any arguments. Let's try it now:
cd
This command typically produces no output, but it silently changes your location in the background. To confirm that you have moved, use the pwd command again:
pwd
The output will now show the path to your home directory:
/home/labex
For the remainder of this lab, we will perform our work inside the ~/project directory. Let's navigate back to it. The tilde character (~) is a special shortcut that represents your home directory. Therefore, ~/project is a path that starts from your home directory and points to the project directory inside it.
Execute the following command to return to the lab's working directory:
cd ~/project
Finally, run pwd one last time to ensure you are back in the correct starting directory for the next step.
pwd
You should see this output, confirming you are back where you started:
/home/labex/project
You have now successfully used pwd to see where you are and cd to move to your home directory and back. These are essential skills for working on any Linux system.