200-901 Question 130
Single answerA network automation engineer is working on a Linux system and needs to perform the following actions:
- Navigate to a directory named 'projects'.
- List all files in the directory, including hidden files.
- Display the value of the 'HOME' environment variable. Which sequence of Bash commands should they use to achieve these steps?
- A
cd projects; ls -a; echo $HOME
- B
cd projects; ls; echo HOME
- C
cd projects; ls -l; echo $HOME
- D
cd projects; ls -a; echo HOME
Show answer and explanation
Correct answer: A
Explanation
In Bash, 'cd' is used to change directories, and 'ls -a' lists all files, including hidden ones (files starting with a dot). Environmental variables like 'HOME' need to be referenced with a '$' symbol, so 'echo $HOME' displays the value of the 'HOME' variable. The correct sequence of commands is 'cd projects; ls -a; echo $HOME'.
- A. Correct.
This is the correct sequence. 'cd projects' navigates to the 'projects' directory, 'ls -a' lists all files including hidden ones, and 'echo $HOME' correctly displays the value of the 'HOME' environment variable by referencing it with the '$' symbol.
- B. Incorrect.
'ls' without the '-a' flag will not include hidden files, and 'echo HOME' will print the string 'HOME' rather than the value of the environment variable.
- C. Incorrect.
'ls -l' lists files in a detailed format but does not include hidden files unless combined with the '-a' option. Additionally, 'echo $HOME' is correct, but the wrong 'ls' option is used here.
- D. Incorrect.
'ls -a' correctly lists hidden files, but 'echo HOME' will print the string 'HOME' rather than the value of the 'HOME' environment variable because the '$' symbol is missing.