nerdexam
LPI

010-150 · Question #79

Which of the following are correct commands for changing the current directory to the user's home? (Choose TWO answers)

The correct answer is B. cd ~ D. cd. Both 'cd' with no arguments and 'cd ~' navigate to the current user's home directory because the shell expands '~' to $HOME and a bare 'cd' defaults to $HOME.

Finding Your Way on a Linux System

Question

Which of the following are correct commands for changing the current directory to the user's home? (Choose TWO answers)

Options

  • Acd /home
  • Bcd ~
  • Ccd ..
  • Dcd
  • Ecd /

How the community answered

(25 responses)
  • A
    8% (2)
  • B
    72% (18)
  • C
    4% (1)
  • E
    16% (4)

Why each option

Both 'cd' with no arguments and 'cd ~' navigate to the current user's home directory because the shell expands '~' to $HOME and a bare 'cd' defaults to $HOME.

Acd /home

'cd /home' changes to the system-wide /home directory, which is the parent container for all user home directories, not the home directory of the current user.

Bcd ~Correct

The tilde '~' undergoes tilde expansion in bash and POSIX shells, being substituted with the value of $HOME before the cd command executes, reliably directing the user to their own home directory.

Ccd ..

'cd ..' moves exactly one level up to the parent of the current working directory, which only reaches the home directory if the user is already one level below it.

DcdCorrect

Invoking 'cd' without any argument is explicitly defined in POSIX and bash as equivalent to 'cd $HOME', making it the most concise way to return to the home directory from any location.

Ecd /

'cd /' changes the working directory to the filesystem root (/), not to any user's home directory.

Concept tested: Navigating to the user home directory in Linux shell

Source: https://www.gnu.org/software/bash/manual/bash.html#Tilde-Expansion

Topics

#cd command#home directory#directory navigation#tilde

Community Discussion

No community discussion yet for this question.

Full 010-150 Practice