This tutorial explains Linux “pwd” command, options and its usage with examples.
The pwd command is considered as one of the most frequently used commands on Linux, AIX, HP-UX, *BSD, and other UNIX like operating systems along with the ls, and cd commands. It can be used for the following purposes under Apple OS X or UNIX or Linux operating systems:
1. Find the full path to the current directory.
2. Store the full path to the current directory in the shell variable.
3. Verify the absolute path.
4. Verify the physical path i.e exclude symbolic links.
use PWD from environment, even if it contains symlinks.
avoid all symlinks.
1. Simple usage of pwd(self explanatory)
$ pwd /usr/local/bin $ cd .. $ pwd /usr/local
2. To display the logical current working directory, enter
$ pwd -L
The -L option cause pwd to use $PWD from environment, even if it contains symlinks. If the contents of the environment variable PWD provide an absolute name of the current directory with no . or .. components, but possibly with symbolic links, then output those contents.
3. Display the physical current working directory (all symbolic links resolved)
For example, ~/bin/ is symbolic link:
$ pwd $ ls -l ~/bin/
lrwxrwxrwx 1 abc abc 35 May 13 2012 /home/abc/bin -> /home/abc/realdata/scripts/utils/
cd to ~/bin/ and verify the current working directory with pwd:
$ cd ~/bin/ $ pwd
To see actual physical current working directory and avoid avoid all symlink called /home/abc/bin, enter:
$ pwd -P
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Apply for Linux Internship
- Apply for Programming Internship
- Buy Information Technology Books
- Practice Programming MCQs
- Buy Linux Books