Difficulty: Easy
Correct Answer: cd
Explanation:
Introduction / Context:
In Unix and Linux, many actions depend on the current working directory. Scripts, relative paths, and shell navigation all assume you know how to move around the filesystem. The question tests which command changes the working directory in POSIX/Bourne-compatible shells, which include sh, bash, ksh, and dash.
Given Data / Assumptions:
Concept / Approach:
Changing the shell’s working directory must be done by a built-in because a separate process cannot modify the parent shell’s state. In POSIX shells, the built-in command for this is cd
. Although some shells also accept chdir
, cd
is the standard portable form. The other names shown either do not exist or are not portable built-ins in this shell family.
Step-by-Step Solution:
cd
is the built-in to change directories.Confirm that cd /path
changes the working directory for the current shell session.Conclude that the correct option is cd
.
Verification / Alternative check:
Type type cd
or help cd
in bash; you will see it is a shell built-in. Running pwd
before and after cd
will verify the directory change.
Why Other Options Are Wrong:
cd
is correct.
Common Pitfalls:
Confusing cd
with external programs; forgetting that cd
with no argument goes to $HOME
; assuming chdir
works everywhere (it is not portable across all Bourne-like shells).
Final Answer:
cd
Discussion & Comments