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
-Land-P. - Deriving the project name or parent directory with
basenamexanddirnamex. - Checking where a cd or
envx -Cactually 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 exitExamples
Print the physical working directory
pwdxKeep symlinks as the shell sees them
pwdx -LResolve every symlink explicitly
cd link && pwdx -PSave the directory in a variable
here=$(pwdx); echox "working in $here"Print only the current directory's name
basenamex "$(pwdx)"Print the parent directory
dirnamex "$(pwdx)"Tell whether the current directory is reached through a symlink
[ "$(pwdx -L)" != "$(pwdx -P)" ] && echox 'inside a symlinked directory'Print the directory a command would run in
envx -C build pwdxShow 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.
- -L, --logical: Use PWD from the environment, even if it contains symlinks.
- -P, --physical: Resolve all symlinks (default).
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: 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