Changing the working directory on Unix/Linux Which standard command changes the shell’s current working directory?

Difficulty: Easy

Correct Answer: cd

Explanation:


Introduction / Context:
Navigating the file system is fundamental to shell usage. Scripts and interactive sessions rely on moving between directories to access files, run commands, and manage projects. The canonical command to change the process’s working directory is short and widely supported across shells.



Given Data / Assumptions:

  • A POSIX-like shell environment is in use (for example, sh, bash, ksh, zsh).
  • We want to change the current working directory for the running shell process.
  • Default shell built-in behavior applies.


Concept / Approach:

The command cd is a shell built-in that changes the current directory of the running shell. It accepts absolute and relative paths. Invoked with no arguments, cd takes you to your home directory. cd - toggles to the previous directory, which is useful for quick back-and-forth navigation.



Step-by-Step Solution:

Display your current directory with pwd.Use cd path to switch (for example, cd /var/log or cd ../project).To return home, run cd with no arguments or cd ~.Use cd - to swap between the current and previous directories.


Verification / Alternative check:

Run pwd before and after cd to confirm the change. Verify permissions, as cd will fail if the user lacks execute permission on the target directory.



Why Other Options Are Wrong:

  • cdir, changedir: not standard shell commands.
  • chdir: a system call name in many languages, but not the standard interactive shell command.
  • None of the above: incorrect because cd is correct and standard.


Common Pitfalls:

Using cd on paths with spaces without quoting; forgetting that cd is a built-in and cannot change the directory of a parent process; misunderstanding permissions required to enter directories.


Final Answer:

cd

Discussion & Comments

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