On Unix/Linux systems, which command prints the absolute path of your current working directory in the shell?

Difficulty: Easy

Correct Answer: pwd

Explanation:


Introduction / Context:
Navigating the filesystem from a terminal requires awareness of where you are. The command that outputs the current working directory is fundamental for scripting, troubleshooting, and documentation of steps in Linux/Unix environments.


Given Data / Assumptions:

  • You are in a POSIX shell (bash, zsh, sh, etc.).
  • You need the full absolute path of the directory you are currently in.
  • Standard coreutils are available.


Concept / Approach:

The pwd command (print working directory) writes the absolute path of the current directory to standard output. It can be used standalone or in scripts to capture context. Some shells also provide an internal builtin with the same name; either way, functionality is the same.


Step-by-Step Solution:

Open a terminal.Type: pwdRead the absolute path returned, such as /home/user/projects.Combine with subshells or scripts as needed, e.g., LOGDIR=$(pwd).


Verification / Alternative check:

Cross-check with ls -ld . and readlink -f . where available. In most cases, pwd suffices and is portable.


Why Other Options Are Wrong:

  • dir: lists directory contents; Windows-style equivalent of ls.
  • prompt $p$g: DOS/Windows prompt formatting; not Unix.
  • path: shows or sets the executable search path in DOS; not current directory.
  • None of the above: incorrect because pwd is correct.


Common Pitfalls:

  • Confusing Windows commands with Unix ones.
  • Relative versus absolute paths; pwd gives absolute by default.


Final Answer:

pwd.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion