Skip to main content

Linux pwd Command

The pwd command is one of the simplest yet most important Linux commands.

It allows you to see your current location inside the Linux filesystem.

As a Linux administrator, developer, ethical hacker, or server owner, you will use this command extremely frequently.


What Does PWD Mean?

pwd stands for:

Print Working Directory

The command prints the absolute path of the directory you are currently working in.


Why is pwd Important?

Linux systems can contain thousands or even millions of files and directories.

Before performing operations like:

  • Deleting files
  • Moving files
  • Creating backups
  • Editing configurations

You should always know your current location.

Using the wrong directory can accidentally damage your system.


Syntax

pwd [OPTION]

Basic Usage

pwd

Example Output:

/home/aayan

This means your current working directory is:

/
└── home
└── aayan

Understanding Current Working Directory

Every terminal session always has one active directory.

Example:

pwd

Output:

/home/aayan

Now move:

cd Documents
pwd

Output:

/home/aayan/Documents

Visual Representation

Linux Filesystem

/
├── home
│ └── aayan
│ ├── Documents
│ ├── Downloads
│ └── Projects
├── etc
├── var
└── root

If you are inside:

/home/aayan/Projects

Then:

pwd

will output:

/home/aayan/Projects

Command Options

The pwd command only contains a few options.


pwd -L

Meaning

Logical Path

Displays the path exactly as you navigated to it.


Syntax

pwd -L

Example

Suppose:

ln -s /home/aayan/projects /home/aayan/dev

Move into:

cd dev

Run:

pwd -L

Output:

/home/aayan/dev

pwd -P

Meaning

Physical Path

Displays the actual directory by resolving symbolic links.


Syntax

pwd -P

Example

Current:

cd dev

Run:

pwd -P

Output:

/home/aayan/projects

Difference Between -L and -P

OptionMeaning
pwd -LShow logical path
pwd -PShow physical path

Real Symbolic Link Example

Create directory:

mkdir real_folder

Create symbolic link:

ln -s real_folder shortcut

Move:

cd shortcut

Logical Path

pwd

Output:

/home/aayan/shortcut

Physical Path

pwd -P

Output:

/home/aayan/real_folder

Practical Examples


Example 1

Check current directory:

pwd

Output:

/home/aayan

Example 2

Move to Downloads:

cd Downloads
pwd

Output:

/home/aayan/Downloads

Example 3

Move to root:

cd /
pwd

Output:

/

Example 4

Move to logs:

cd /var/log
pwd

Output:

/var/log

Understanding Absolute Paths

pwd always returns an absolute path.

Absolute paths always begin with:

/

Examples:

/home
/etc
/var/log
/usr/bin

PWD and Relative Paths

Suppose:

Current directory:

/home/aayan

Execute:

cd Documents

Linux automatically interprets it as:

/home/aayan/Documents

Use:

pwd

to verify your location.


Real Server Examples


PocketMine-MP Hosting

Server location:

/home/minecraft/server

Verify:

cd /home/minecraft/server
pwd

Output:

/home/minecraft/server

Plugins Directory

cd plugins
pwd

Output:

/home/minecraft/server/plugins

World Folder

cd worlds
pwd

Output:

/home/minecraft/server/worlds

Web Hosting Example

Website files:

/var/www/html

Check location:

cd /var/www/html
pwd

PHP Configuration Example

cd /etc/php
pwd

Nginx Example

cd /etc/nginx
pwd

Ethical Hacking Example

Move to wordlists:

cd /usr/share/wordlists
pwd

Output:

/usr/share/wordlists

Common Mistakes


Mistake 1

Deleting files without checking location.

Example:

rm -rf *

Always verify first:

pwd

Mistake 2

Confusing:

/

with:

/root

Remember:

DirectoryMeaning
/Root filesystem
/rootRoot user's home

Mistake 3

Getting lost in deeply nested directories.

Solution:

pwd

Combining Commands

Example:

cd Documents && pwd

Output:

/home/aayan/Documents

Example:

mkdir Test && cd Test && pwd

Output:

/home/aayan/Test

Command Flags Summary

CommandDescription
pwdPrint current directory
pwd -LDisplay logical path
pwd -PDisplay physical path

Interview Questions


What does pwd stand for?

Answer:

Print Working Directory

Does pwd display relative paths?

No.

It always displays absolute paths.


Difference between pwd -L and pwd -P?

-L:

Logical path

-P:

Physical path

Why is pwd important?

To verify location before performing operations.


Exercises


Exercise 1

Display your current directory.

pwd

Exercise 2

Navigate to:

/etc

Then display location.


Exercise 3

Navigate to:

/var/log

Then print directory.


Exercise 4

Create:

mkdir -p Linux/Test/Folder

Move there and run:

pwd

Exercise 5

Create symbolic links and test:

pwd -L
pwd -P

Mini Project

Create:

LinuxLab
├── Documents
├── Projects
└── Scripts

Navigate through all directories and use pwd to understand Linux paths.


Key Takeaways

pwd means Print Working Directory

✅ Displays your current location.

✅ Returns an absolute path.

✅ Useful for system administration, ethical hacking and server management.

✅ Always use pwd before dangerous commands like:

rm
mv
cp
chmod

Summary

The pwd command is simple but extremely important.

Understanding your current location inside Linux is essential before performing any administrative task.

Mastering pwd will make learning other Linux commands much easier.


Next Chapter

➡ Linux ls Command

Learn how to list files and directories in Linux.