Bash – Why pwd does not accept long options like –physical

bashpwdrhel

When I display the manual for pwd command, it says that long options like --physical are supported

$ man pwd
PWD(1)                           User Commands                          PWD(1)

NAME
       pwd - print name of current/working directory

SYNOPSIS
       pwd [OPTION]...

DESCRIPTION
       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

However, it fails when I type the following

$ pwd --physical
-bash: pwd: --: invalid option
pwd: usage: pwd [-LP]

Why are long options not working for me?

I'm using RHEL 6.4. No alias for pwd is configured. Looks like it's standard pwd:

$ which pwd
/bin/pwd

Best Answer

bash has a built-in command pwd which is what you are using when you simply type pwd into your shell.

To get the pwd as described by the manpage, you need force use of the external command. You can do this by specifying the full path to the executable (/bin/pwd in your case) or by prepending env before the line: env pwd, which starts the env command which can be used to add settings to the environment (but which is not done here) and then env starts the command specified. As env doesn't have a builtin pwd, the "real" /bin/pwd is executed.

The advantage of the builtin pwd in bash is that bash keeps track of the current directory, so getting the value is at zero cost, whereas the external command needs to search up through the filesystem to determine the path, which is much more IO intensive.

Related Question