```{index} single: Cwd; Perl module ``` # Cwd ```{pperl-module-badges} Cwd ``` Report the current working directory and resolve paths to their absolute, symlink-free form. This module provides the four "where am I" functions (`cwd`, `getcwd`, `fastcwd`, `fastgetcwd`), the three "make this path absolute" functions (`abs_path`, `realpath`, `fast_abs_path`), and a `chdir` that keeps `$ENV{PWD}` in sync. Two groups of tradeoffs matter when choosing between them. **Current directory.** `getcwd` is the most portable and safe call — it asks the kernel via the POSIX `getcwd(3)` interface and never leaves the process anywhere surprising. `fastcwd` walks the tree with repeated `chdir('..')` and is faster on deep paths, but if a parent directory disappears mid-walk (or is unreadable) it returns `undef` and may leave the process in a different directory than it started. `cwd` picks the most natural form for the platform; on Linux it is effectively `getcwd`. `fastgetcwd` is a synonym for `cwd`. **Path resolution.** `abs_path` canonicalises a path, resolving symlinks and `.`/`..` components. `realpath` is its POSIX-style alias — same function, different name. `fast_abs_path` is the faster variant that drops the "non-existent leaf" fallback: it returns `undef` the moment any component fails to resolve, where `abs_path` will still return a usable path when only the final leaf is missing. `chdir` changes directory and, on success, writes the new absolute path to `$ENV{PWD}` so child processes inherit a consistent view. ## Functions ### Current directory #### [`cwd`](Cwd/cwd) Return the absolute path of the process's current working directory. #### [`chdir`](Cwd/chdir) Change the process's current working directory, and update `$ENV{PWD}` to match. ### Path resolution #### [`abs_path`](Cwd/abs_path) Canonicalise a path: resolve symlinks, `.`, and `..`, and return the absolute form. #### [`fast_abs_path`](Cwd/fast_abs_path) Canonicalise a path strictly: resolve symlinks and `.`/`..`, or return `undef` if any component is missing. ```{toctree} :hidden: :maxdepth: 1 Cwd/cwd Cwd/abs_path Cwd/fast_abs_path Cwd/chdir ```