Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux pwd Command: Show Current Path

The pwd (print working directory) command is a simple yet essential tool for navigating the Linux file system. This tutorial will introduce you to the pwd command, its usage, and a practical example.

  • Basic Usage

The basic syntax for the pwd command is as follows:

pwd [options]

By default, pwd displays the full path to your current working directory.

  • Options

The pwd command supports two main options:

  • -L or --logical: Displays the logical current directory, resolving symbolic links (default behavior)
  • -P or --physical: Displays the physical current directory, without resolving symbolic links
  • Examples

Here is a practical example of using the pwd command:

  • Display the current working directory:

    pwd
    

    Output:

    /home/john/Documents
    
  • Navigating Directories

You can use the cd (change directory) command to navigate between directories in your Linux file system. For example:

  • Change to the /var/log directory:

    cd /var/log
    
  • Move up one level in the directory tree:

    cd ..
    
  • Move to the user's home directory:

    cd ~
    
  • Go back to the previous working directory:

    cd -
    

After using the cd command, you can use pwd to verify your current location in the file system.

In conclusion, the pwd command is a fundamental tool for working with the Linux file system. By understanding its basic usage and options, you can easily keep track of your current location while navigating the file system.

  1. How to use pwd to display the current path: The pwd command prints the current working directory. For example:

    pwd
    
  2. Viewing current working directory in Linux with pwd: Use pwd to view the current working directory. For example:

    pwd
    
  3. Using pwd in shell scripts on Linux: Incorporate pwd in shell scripts to get the current directory path dynamically. For instance:

    #!/bin/bash
    current_path=$(pwd)
    echo "Current path: $current_path"
    
  4. Advanced options for the pwd command in Linux: pwd doesn't have many advanced options. However, you can use it with other commands or in scripts to enhance functionality.

  5. Getting absolute path with pwd in Linux: To get the absolute path, use pwd in combination with the readlink command. For example:

    absolute_path=$(readlink -f "$(pwd)")
    echo "Absolute path: $absolute_path"
    
  6. pwd vs. cd: differences in Linux navigation commands:

    • pwd: Prints the current working directory without changing it.

      pwd
      
    • cd: Changes the current working directory.

      cd /path/to/directory
      
  7. Customizing the behavior of pwd in the terminal: pwd itself doesn't have many customization options. You can, however, create aliases or functions in your shell configuration file (e.g., .bashrc or .zshrc) to add additional functionality or formatting.

    For example, to create a custom mypwd command that also lists files:

    mypwd() {
        pwd
        ls -a
    }
    

    Save and reload your shell configuration file to use the custom command:

    source ~/.bashrc   # For Bash
    source ~/.zshrc    # For Zsh