• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 17, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

15 ‘pwd’ (Print Working Directory) Command Examples in Linux

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
29
VIEWS
Share on FacebookShare on Twitter

Contents

  1. What is pwd?
    1. Basic syntax of pwd:
    2. Options used with pwd
  2. Conclusion

For those working with Linux command Line, command ‘pwd‘ is very helpful, which tells where you are – in which directory, starting from the root (/). Specially for Linux newbies, who may get lost amidst of directories in command Line Interface while navigation, command ‘pwd‘ comes to rescue.

15 ‘pwd’ (Print Working Directory) Command Examples in Linux

15 pwd Command Examples

What is pwd?

‘pwd‘ stands for ‘Print Working Directory‘. As the name states, command ‘pwd‘ prints the current working directory or simply the directory user is, at present. It prints the current directory name with the complete path starting from root (/). This command is built in shell command and is available on most of the shell – bash, Bourne shell, ksh,zsh, etc.

Basic syntax of pwd:
# pwd [OPTION]
Options used with pwd
 Options  Description
 -L (logical)  Use PWD from environment, even if it contains symbolic links
 -P (physical)  Avoid all symbolic links
 –help  Display this help and exit
 –version  Output version information and exit

If both ‘-L‘ and ‘-P‘ options are used, option ‘L‘ is taken into priority. If no option is specified at the prompt, pwd will avoid all symlinks, i.e., take option ‘-P‘ into account.

Exit status of command pwd:

0 Success
Non-zero Failure

This article aims at providing you a deep insight of Linux command ‘pwd‘ with practical examples.

1. Print your current working directory.

[email protected]:~$ /bin/pwd

/home/avi
15 ‘pwd’ (Print Working Directory) Command Examples in Linux

Print Working Directory

2. Create a symbolic link of a folder (say /var/www/html into your home directory as htm). Move to the newly created directory and print working directory with symbolic links and without symbolic links.

Create a symbolic link of folder /var/www/html as htm in your home directory and move to it.

[email protected]:~$ ln -s /var/www/html/ htm
[email protected]:~$ cd htm
15 ‘pwd’ (Print Working Directory) Command Examples in Linux

Create Symbolic Link

3. Print working directory from environment even if it contains symlinks.

[email protected]:~$ /bin/pwd -L

/home/avi/htm
15 ‘pwd’ (Print Working Directory) Command Examples in Linux

Print Current Working Directory

4. Print actual physical current working directory by resolving all symbolic links.

[email protected]:~$ /bin/pwd -P

/var/www/html
15 ‘pwd’ (Print Working Directory) Command Examples in Linux

Print Physical Working Directory

5. Check if the output of command “pwd” and “pwd -P” are same or not i.e., if no options are given at run-time does “pwd” takes option -P into account or not, automatically.

[email protected]:~$ /bin/pwd

/var/www/html
15 ‘pwd’ (Print Working Directory) Command Examples in Linux

Check pwd Output

Result: It’s clear from the above output of example 4 and 5 (both result are same) thus, when no options are specified with command “pwd”, it automatically takes option “-P” into account.

6. Print version of your ‘pwd’ command.

[email protected]:~$ /bin/pwd --version

pwd (GNU coreutils) 8.23
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jim Meyering.
15 &#8216;pwd&#8217; (Print Working Directory) Command Examples in Linux

Check pwd Version

Note: A ‘pwd’ command is often used without options and never used with arguments.

Important: You might have noticed that we are executing the above command as “/bin/pwd” and not “pwd”.

So what’s the difference? Well “pwd” alone means shell built-in pwd. Your shell may have different version of pwd. Please refer manual. When we are using /bin/pwd, we are calling the binary version of that command. Both the shell and the binary version of command Prints Current Working Directory, though the binary version have more options.

7. Print all the locations containing executable named pwd.

[email protected]:~$ type -a pwd

pwd is a shell builtin
pwd is /bin/pwd
15 &#8216;pwd&#8217; (Print Working Directory) Command Examples in Linux

Print Executable Locations

8. Store the value of “pwd” command in variable (say a), and print its value from the variable (important for shell scripting perspective).

[email protected]:~$ a=$(pwd)
[email protected]:~$ echo "Current working directory is : $a"

Current working directory is : /home/avi
15 &#8216;pwd&#8217; (Print Working Directory) Command Examples in Linux

Store Pwd Value in Variable

Alternatively, we can use printf, in the above example.

9. Change current working directory to anything (say /home) and display it in command line prompt. Execute a command (say ‘ls‘) to verify is everything is OK.

[email protected]:~$ cd /home
[email protected]:~$ PS1='$pwd> '		[Notice single quotes in the example]
> ls
15 &#8216;pwd&#8217; (Print Working Directory) Command Examples in Linux

Change Current Working Directory

10. Set multi-line command line prompt (say something like below).

/home
123#Hello#!

And then execute a command (say ls) to check is everything is OK.

[email protected]:~$ PS1='
> $PWD
$ 123#Hello#!
$ '

/home
123#Hello#!
15 &#8216;pwd&#8217; (Print Working Directory) Command Examples in Linux

Set Multi Commandline Prompt

11. Check the current working directory and previous working directory in one GO!

[email protected]:~$ echo “$PWD $OLDPWD”

/home /home/avi
15 &#8216;pwd&#8217; (Print Working Directory) Command Examples in Linux

Check Present Previous Working Directory

12. What is the absolute path (starting from /) of the pwd binary file.

/bin/pwd 

13. What is the absolute path (starting from /) of the pwd source file.

/usr/include/pwd.h 

14. Print the absolute path (starting from /) of the pwd manual pages file.

/usr/share/man/man1/pwd.1.gz

15. Write a shell script analyses current directory (say tecmint) in your home directory. If you are under directory tecmint it output “Well! You are in tecmint directory” and then print “Good Bye” else create a directory tecmint under your home directory and ask you to cd to it.

Let’s first create a ‘tecmint’ directory, under it create a following shell script file with name ‘pwd.sh’.

[email protected]:~$ mkdir tecmint
[email protected]:~$ cd tecmint
[email protected]:~$ nano pwd.sh

Next, add the following script to the pwd.sh file.

#!/bin/bash

x="$(pwd)"
if [ "$x" == "/home/$USER/tecmint" ]
then
     {
      echo "Well you are in tecmint directory"
      echo "Good Bye"
     }
else
     {
      mkdir /home/$USER/tecmint
      echo "Created Directory tecmint you may now cd to it"
     }
fi

Give execute permission and run it.

[email protected]:~$ chmod 755 pwd.sh
[email protected]:~$ ./pwd.sh

Well you are in tecmint directory
Good Bye

Conclusion

pwd is one of the simplest yet most popular and most widely used command. A good command over pwd is basic to use Linux terminal. That’s all for now. I’ll be here again with another interesting article soon, till then stay tuned and connected to Tecmint.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

13 Linux Network Configuration and Troubleshooting Commands

Next Post

4 Ways to Batch Convert Your PNG to JPG and Vice-Versa

Next Post

4 Ways to Batch Convert Your PNG to JPG and Vice-Versa

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet