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 commandpwd
which is what you are using when you simply typepwd
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 prependingenv
before the line:env pwd
, which starts theenv
command which can be used to add settings to the environment (but which is not done here) and thenenv
starts the command specified. Asenv
doesn't have a builtinpwd
, the "real"/bin/pwd
is executed.The advantage of the builtin
pwd
in bash is thatbash
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.