Skip to main content

pwd — Print Working Directory

The pwd command is one of the simplest Linux utilities — but also one of the most important.

In Linux and Unix systems, every command runs relative to a directory.
If you don’t know where you are in the filesystem, you risk:

  • Editing the wrong file
  • Deleting the wrong directory
  • Backing up the wrong location
  • Running scripts in unintended paths

pwd solves that instantly by printing your current working directory — the exact absolute path your shell session is operating in.

For DevOps engineers, VPS administrators, and WordPress operators, pwd is a safety checkpoint.

What pwd Actually Does​

pwd prints the absolute path of your current directory.

Example:

pwd

Output:

/var/www/html

This means all relative operations (like rm file.txt) will occur inside /var/www/html.

It does not list files. It does not modify anything. It simply reports your current location in the filesystem tree.

Why pwd Matters in Real Systems​

1. Prevents Catastrophic Mistakes​

Before running:

rm -rf *

You should run:

pwd

Deleting /var/www/html/* is very different from deleting /etc/*.

2. Essential in WordPress VPS Management​

Typical WordPress paths:

  • /var/www/html
  • /var/www/html/wp-content/plugins
  • /var/www/html/wp-content/themes
  • /var/www/html/wp-content/uploads

Before editing wp-config.php or changing permissions, confirm location with pwd.

3. Critical for Automation & Scripts​

Scripts behave differently depending on execution directory.

echo "Running in: $(pwd)"

This avoids confusion when debugging cron jobs or deployment scripts.

Core Syntax​

pwd [OPTION]

Available Options​

OptionMeaningExampleExpected Output
---
(none)Print full absolute pathpwd/var/www/html
-LLogical path (keeps symlinks)pwd -L/home/user/wordpress
-PPhysical path (resolves symlinks)pwd -P/mnt/data/wordpress
--helpShow helppwd --helpUsage info
--versionShow versionpwd --versionGNU coreutils version

Logical vs Physical Paths (Important)​

Logical Path (-L)​

Shows the path as navigated, even if it contains symbolic links.

Example:

cd /var/www/latest
pwd -L

Output:

/var/www/latest

Physical Path (-P)​

Resolves symlinks and shows the real directory.

pwd -P

Output:

/var/www/releases/2025-09

This is extremely important in deployment pipelines using symlink switching (Capistrano-style releases).

Implementation Steps (VPS Context)​

  1. SSH into your VPS.
  2. Run pwd immediately.
  3. Use cd to navigate.
  4. Run pwd again to confirm.
  5. Before running destructive commands, verify location again.

Best Practices​

Always Confirm Before Destructive Commands​

pwd && rm -rf testdir/

Use pwd -P in Symlinked Environments​

Especially in:

  • Shared hosting
  • Mounted storage
  • Docker bind mounts
  • WordPress release deployments

Store Current Directory in Variables​

CURR_DIR=$(pwd)
echo "We are in $CURR_DIR"

Useful for:

  • Backup scripts
  • Log output
  • Debugging

Practical Examples (WordPress & VPS Focus)​

1. Basic check​

pwd

Output:

/root

2. Move to WordPress root​

cd /var/www/html
pwd

Output:

/var/www/html

3. Home directory​

cd ~
pwd

Output:

/home/username

4. Logical path​

pwd -L

Output:

/home/user/wordpress

5. Physical path​

pwd -P

Output:

/mnt/data/wordpress

6. Combine with ls​

echo "Current dir: $(pwd)" && ls

7. Store in variable​

CURRENT=$(pwd)
echo $CURRENT

8. Confirm before deletion​

pwd && rm -rf testdir/

9. Inside plugins directory​

cd /var/www/html/wp-content/plugins
pwd

10. Inside themes directory​

cd /var/www/html/wp-content/themes
pwd

11. Inside uploads directory​

cd /var/www/html/wp-content/uploads
pwd
cd /var/www/latest
pwd -P

13. Log directory check​

cd /var/log/nginx
pwd

14. Script-friendly output​

echo "Running script in $(pwd)"

15. Remote execution​

ssh user@server "pwd"

Troubleshooting Matrix​

ProblemCauseFix
---
Unexpected pathInside symlinkUse pwd -P
pwd not foundCoreutils missing (rare)Install coreutils
Wrong directory usedPath not verifiedAlways run pwd first

Cheat Sheet​

pwd # Show current directory
pwd -L # Logical path (symlinks intact)
pwd -P # Physical path (resolve symlinks)
pwd --help # Help info
pwd --version # Version info

Final Perspective​

pwd is simple — but it is your first line of defense.

Before modifying:

  • Files
  • WordPress configurations
  • System services
  • Logs
  • Backups

Always verify location.

In Linux administration, knowing where you are is as important as knowing what you are doing.

Mini Knowledge Check​

  1. What does pwd stand for?
  2. What is the difference between pwd -L and pwd -P?
  3. Why should you run pwd before rm -rf?
  4. How do you store the current directory in a variable?