When you are navigating through an Ubuntu server using a command-line interface, you do not have the luxury of a visual file explorer showing you a neat folder hierarchy on the left side of your screen. If you have been jumping between dozens of different configuration directories, it is incredibly easy to completely lose track of exactly where you are on the hard drive.
If you try to run a script or delete a file without knowing your exact location, you risk triggering a catastrophic error on the server.
Ubuntu provides an instantaneous, foolproof command designed specifically to tell you exactly where you are standing in the folder structure.
The ‘pwd’ Command
The pwd command stands for Print Working Directory. It does exactly what the name implies: it prints the absolute path of your current location directly to the terminal screen.
- Open your terminal or SSH into your Ubuntu server.
- Type the following three letters and press Enter:
pwd
The terminal will instantly output a single line of text. For example:
/var/www/html/public_html
This output is your “absolute path.” It tells you that you are currently standing in a folder called public_html, which is inside a folder called html, which is inside a folder called www, which is inside a folder called var, which sits at the very root (/) of the entire hard drive.
Why the Terminal Prompt Isn’t Enough
You might wonder why you need a dedicated command when the terminal usually tells you the folder name right in the prompt (e.g., user@server:~/documents$).
The problem is that the default Ubuntu prompt only displays the name of the specific folder you are in, not the full path to get there.
For example, if the prompt says you are in a folder called config, that is dangerous. Are you in your personal /home/user/config folder, or are you in the system-critical /etc/apache2/config folder? You cannot know for sure just by looking at the prompt.
Running the pwd command eliminates all ambiguity, guaranteeing that any destructive commands you are about to run (like deleting all files with a wildcard) are targeting the exact directory you intended.