Pwd Command in Linux (Current Working Directory)

Pwd Command in Linux (Current Working Directory)

What is pwd?

The pwd command stands for “Print Working Directory”. It shows the full path to your current directory — i.e., where you are located in the filesystem.

Syntax

pwd [OPTION]

The command is simple and usually run without options.

Basic Usage

pwd

Output Example:

/home/username/Documents

This tells you that you're currently inside the Documents directory of the user username.

Why Use pwd?

  • To know your current location in the terminal

  • Helps with navigating complex directory structures

  • Useful in scripts for debugging paths

Step-by-Step Examples

Step 1: Open Terminal

Start your terminal on any Linux distribution.

Step 2: Run pwd

pwd

Shows the current full directory path.

Step 3: Change Directory & Use pwd

cd /etc pwd

Output:

/etc

Now you know you are inside the /etc directory.

Step 4: Use with Other Commands

You can combine pwd with other commands in scripts:

echo "You are in: $(pwd)"

Options with pwd

The most common usage is without options, but you may come across:

OptionDescription
-L(Logical) Shows the logical path (default)
-P(Physical) Resolves symlinks to show real path

Example:

pwd -P

Real Use Cases

  • Find your location in a nested folder:

    cd /var/log/apache2 pwd
  • Add path to logs or scripts:

    echo "Current Path: $(pwd)" >> mylog.txt

Summary

CommandDescription
pwdShows current working directory
pwd -PShows physical path (resolves links)
pwd -LShows logical path (default)

Let me know if you'd like this as a printable cheat sheet or if you need a practice exercise using pwd, cd, and ls together!

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close