How To Use pwd Command In Linux / UNIX {with examples}

The pwd (Print Working Directory) command is used in Linux and Unix systems to print the current working directory. The current working directory is the directory where the shell is currently located.

Here are some examples of how to use the pwd command:

  1. Basic usage:
pwd

This will print the full path of the current working directory.

  1. Output format:
pwd -P

The -P option prints the physical directory, without any symbolic links.

pwd -L

The -L option prints the logical directory, with all symbolic links resolved.

  1. In shell scripts:
#!/bin/bash

current_dir=$(pwd)

echo "The current working directory is $current_dir"

This shell script uses the pwd command to store the current working directory in a variable, which can then be used in other commands.

The pwd command is a simple and useful tool that can be used to find out the current working directory in Linux and Unix systems.

Leave a Comment