This tutorial explains Linux “pwd” command, options and its usage with examples.
Description:
In Unix-like and some other operating systems, the pwd command (print working directory) is used to output the path of the current working directory.
The command is a shell builtin in certain Unix shells such as sh, and bash. It can be implemented easily with the POSIX C functions getcwd() and/or getwd().
Users who are familiar with MS-DOS or the Windows command prompt may type cd alone to print the working directory. However, typing cd alone in Linux and Unix will return you to the home directory.
Synopsis:
pwd [OPTION]…
OPTIONS:
-L
Logical Links
-P
Physical Links
Examples:
1. To print name of current/working directory(pwd):
sanfoundry-> pwd /home/himanshu sanfoundry-> cd SAN/ sanfoundry-> pwd /home/himanshu/SAN sanfoundry-> /bin/pwd /home/himanshu/SAN
2. To show the full path when symlinks are there(pwd OR pwd -L):
sanfoundry-> ln -s folder/ linked_folder sanfoundry-> ls -l linked_folder lrwxrwxrwx 1 himanshu himanshu 7 Jul 28 17:15 linked_folder -> folder/ sanfoundry-> cd linked_folder sanfoundry-> pwd /home/himanshu/SAN/linked_folder sanfoundry-> pwd -L /home/himanshu/SAN/linked_folder
Here “-L” stands for “–logical” and we can see that whole path upto the linked folder is shown with “-L” option.
But if you want to see the path to the original folder for the linked folder use “-P” option.
3. To see the original folder of the linked folder(pwd -P):
sanfoundry-> ln -s folder/ linked_folder sanfoundry-> ls -l linked_folder lrwxrwxrwx 1 himanshu himanshu 7 Jul 28 17:15 linked_folder -> folder/ sanfoundry-> cd linked_folder sanfoundry-> pwd /home/himanshu/SAN/linked_folder sanfoundry-> pwd -P /home/himanshu/SAN/folder
Here “-P” stands for “–physical” ans we can see that the path upto the folder directory is shown instead to the path of the linked directory linked_folder.
Note:Shell pwd vs /bin/pwd:
To use the binary version, type full path /bin/pwd:
sanfoundry-> /bin/pwd /home/himanshu/SAN
By typing pwd, you end up using the shell builtin provided by bash or ksh:
pwd
4. To see all locations containing an executable named pwd:
sanfoundry-> type -a pwd pwd is a shell builtin pwd is /bin/pwd
The /bin/pwd version of pwd command has a two more additional options.
5. To see the version of pwd command:
sanfoundry-> /bin/pwd --version pwd (GNU coreutils) 8.13 Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . 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.
6. To get the help:
sanfoundry-> /bin/pwd --help Usage: /bin/pwd [OPTION]... Print the full filename of the current working directory. -L, --logical use PWD from environment, even if it contains symlinks -P, --physical avoid all symlinks --help display this help and exit --version output version information and exit NOTE: your shell may have its own version of pwd, which usually supersedes the version described here. Please refer to your shells documentation for details about the options it supports. Report pwd bugs to bug-coreutils@gnu.org GNU coreutils home page: General help using GNU software: For complete documentation, run: info coreutils pwd invocation'
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Apply for Linux Internship
- Practice Programming MCQs
- Buy Linux Books
- Buy Information Technology Books
- Apply for Programming Internship