Introduction
Hello! In this article, we’ll learn about the pwd command.
pwd stands for “Print Working Directory” - basically it’s a command that tells you “where am I right now?” Super simple, but super useful.
What is the pwd Command?
When you move around different directories in Linux, you sometimes think “Wait, where am I right now?” That’s when you use the pwd command.
When you run it, it displays the absolute path of your current directory right away.
Basic Syntax
|
|
Honestly, you’ll mostly use it without any options.
Main Options
| Option | Description |
|---|---|
-L |
Show path including symbolic links (default) |
-P |
Show actual path with symbolic links resolved |
To be honest, I rarely use options with this command.
Usage Examples
Example 1: Basic Usage
|
|
Output:
|
|
That’s it. Simple, right?
Example 2: Using with cd
|
|
Output:
|
|
A common pattern is using pwd to confirm where you are after moving.
Example 3: With Symbolic Links
|
|
Output:
|
|
|
|
Output:
|
|
When using symbolic links, the -P option shows you the real path.
Tips & Notes
-
Combine with cd: It’s handy to check if you actually arrived at your intended destination after changing directories
1 2cd ~/projects/myapp pwd # Confirm location -
Use in shell scripts: Often used in scripts when you need to get the current directory
1 2 3#!/bin/bash CURRENT_DIR=$(pwd) echo "Current directory: $CURRENT_DIR" -
Displayed in prompt: Actually, most terminals already show your current directory in the prompt
1user@hostname:~/documents$But
pwdis still useful when you want to see the full path or use it in scripts. -
PWD environment variable: The same information is also stored in the
$PWDenvironment variable1echo $PWD
Practical Usage
Return to Original Directory in Scripts
|
|
This is a common pattern in scripts.
When Lost in Deep Hierarchies
|
|
When you’re deep in directory hierarchies and thinking “Where am I?”, just run this and you’re good.
Summary
In this article, we learned about the pwd command.
Key Points:
pwdshows you the full path of your current directory- Basically just use it without options
- Frequently used in shell scripts too
- Your lifesaver when you’re lost
It’s a super simple command, but you’ll use it often. Good to remember cd and pwd as a set - they’re quite handy together.
Keep learning Linux commands!