Skip to Content
gnux

pwdx

Print the full name of the current working directory.

Mirrors GNU pwd. Run it as pwdx, or as gnux pwdx.

Synopsis

pwdx [OPTION]...

GNU reference

Description

pwdx prints the absolute path of the current working directory. With -P (the default) every symbolic link in the path is resolved; with -L it prints the value of the PWD environment variable when that names the current directory, preserving the symlinks the shell walked through. If both are given, the last one wins in GNU pwd; pwdx prefers -L.

Permissions

Needs search permission on every directory leading to the current one to resolve it physically.

Use cases

  • Capturing the working directory in a script.
  • Finding the real location behind a symlinked directory with -P.
  • Keeping the symlinked path the user navigated through with -L, for messages or relative links.
  • Detecting whether the current directory is reached through a symlink by comparing -L and -P.
  • Deriving the project name or parent directory with basenamex and dirnamex.
  • Checking where a cd or envx -C actually landed in a script.

Flags

      --help       display this help and exit
  -L, --logical    use PWD from the environment, even if it contains symlinks
  -P, --physical   resolve all symlinks (default)
      --version    output version information and exit

Examples

pwdx
pwdx -L
cd link && pwdx -P

Save the directory in a variable

here=$(pwdx); echox "working in $here"
basenamex "$(pwdx)"
dirnamex "$(pwdx)"
[ "$(pwdx -L)" != "$(pwdx -P)" ] && echox 'inside a symlinked directory'
envx -C build pwdx

Show where cd leads inside the gnux shell

gnux shell -c 'cd docs; pwdx'

Options

Each option has a page of its own, with its usage and examples.

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

pwdx --help                # options, first examples, exit status
gnux help pwdx             # this page: the full manual
gnux help pwdx --OPTION    # one option in depth, with its examples

See also

On this page