getcwd - Linux


getcwd is a Linux command used to get the current working directory. It is a common utility for scripting and automation tasks where the current directory’s absolute path is needed.


getcwd [options]


| Option | Description | Default |
| –absolute | Print the absolute path | Yes |
| –logical | Resolve symbolic links and print the logical path | No |
| –help | Display usage information and exit | – |
| –version | Display version information and exit | – |


  • Get the current working directory’s absolute path:
$ getcwd --absolute
  • Get the current working directory’s logical path:
$ getcwd --logical
  • Use the output in a script:
cwd=$(getcwd --absolute)
echo "Current directory: $cwd"

Common Issues

  • Empty output: If no path is specified, getcwd will print nothing (an empty string).
  • Incorrect path: The printed path may not be correct if the current working directory has changed after getcwd was called.


getcwd can be used in conjunction with other commands, such as:

  • cd: Change the current working directory.
  • ls: List the contents of the current directory.
  • mkdir: Create a new directory.

Related Commands

  • pwd: Print the current working directory in a more user-friendly format.
  • realpath: Resolve symbolic links and print the absolute path.