2. Which of the following is the correct command to change directory to the home folder in Linux?
easy
A. cd /home
B. ls ~
C. cd ~
D. pwd ~
Solution
Step 1: Identify the command to change directory
The command to change directory is cd.
Step 2: Recognize the shortcut for home directory
The tilde ~ represents the home directory, so cd ~ moves you there.
Final Answer:
cd ~ -> Option C
Quick Check:
cd ~ changes to home [OK]
Hint: Use cd ~ to go home quickly [OK]
Common Mistakes:
Using ls ~ which lists files, not changes directory
Using pwd ~ which is invalid syntax
Using cd /home which may not be the user's home
3. What will be the output of the following commands sequence?
cd /tmp
pwd
cd ..
pwd
medium
A. /tmp
/
B. /tmp
/tmp
C. /
/tmp
D. /
/
Solution
Step 1: Execute cd /tmp and pwd
Changing directory to /tmp and printing working directory shows /tmp.
Step 2: Execute cd .. and pwd
Moving up one directory from /tmp goes to /. Printing working directory now shows /.
Final Answer:
/tmp
/
-> Option A
Quick Check:
cd /tmp then cd .. moves to root [OK]
Hint: Remember: cd .. moves up one folder [OK]
Common Mistakes:
Thinking cd .. stays in the same folder
Confusing output order
Assuming pwd shows previous directory
4. You run the command cd documents but get an error: bash: cd: documents: No such file or directory. What is the most likely cause?
medium
A. The folder 'documents' does not exist in the current directory.
B. The 'cd' command is misspelled.
C. You need to use 'ls' before 'cd'.
D. You are already in the documents folder.
Solution
Step 1: Understand the error message
The error says the folder 'documents' does not exist in the current directory.
Step 2: Check the folder existence
If the folder is not there, cd documents will fail with this error.
Final Answer:
The folder 'documents' does not exist in the current directory. -> Option A
Quick Check:
Error means folder missing [OK]
Hint: Check folder exists before cd [OK]
Common Mistakes:
Assuming 'cd' is misspelled
Thinking 'ls' must run before 'cd'
Believing you are already inside the folder
5. You want to write a script that lists all files in your home directory, then moves into the Documents folder inside home, and finally prints the current directory path. Which sequence of commands is correct?
hard
A. cd ~/Documents
ls ~
pwd
B. ls ~
cd ~/Documents
pwd
C. pwd
cd ~
ls Documents
D. ls Documents
cd ~
pwd
Solution
Step 1: List files in home directory
The command ls ~ lists files in the home directory.
Step 2: Change directory to Documents inside home
cd ~/Documents moves into the Documents folder inside home.
Step 3: Print current directory path
pwd shows the current directory, which should now be Documents.
Final Answer:
ls ~
cd ~/Documents
pwd -> Option B
Quick Check:
List home, cd Documents, print path [OK]
Hint: List home first, then cd Documents, then pwd [OK]
Common Mistakes:
Changing directory before listing home files
Listing wrong folder
Printing path before changing directory
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.