suppose I have a symlink chain A -> B -> C
when I type pwd, it could show me in A, B, or C depending how I get here.
How do I show the physical directory address, i.e. not represented by any symlinks?
suppose I have a symlink chain A -> B -> C
when I type pwd, it could show me in A, B, or C depending how I get here.
How do I show the physical directory address, i.e. not represented by any symlinks?
Have you tried
pwd -P
It works for me (using zsh).
$ ls -l
drwxrwxr-x 2 xxxxxxx xxxxxxx 4096 Aug 28 10:14 a
lrwxrwxrwx 1 xxxxxxx xxxxxxx 1 Aug 28 10:15 b -> a
$ cd b
$ pwd
/home/xxxxxxx/temp/b
$ pwd -P
/home/xxxxxxx/temp/a
**pwd -P**
.readlink -f
. (man info coreutils readlink
).realpath .
but even to any other file realpath \my\long\path\file.ext
Your shell
usually has a built-in pwd command that is used instead of /bin/pwd
.
If you write in a shell type pwd
it will answer if your shell provide you a built-in version.
For the correct help you can refer to
man pwd
usually for the \bin\pwd
commandman bash
and after search for pwd
for the built in version.man <TheShellName>
for the other shells (zsh,csh,tcsh...)From man bash
e.g. you can read
pwd [-LP]
Print the absolute pathname of the current working directory. The pathname printed contains no symbolic links if the -P option is supplied or the -o physical option to the set builtin command is enabled. If the -L option is used, the pathname printed may contain symbolic links. The return status is 0 unless an error occurs while reading the name of the current directory or an invalid option is supplied.
You can use readlink (if available in your distro) from the current directory:
$ readlink -f .
or with a full path:
$ readlink -f /my-dir/with-some-link
rhel/centos provide it in coreutils pkg. hth.