📖 Scenario: Imagine you just started using a new computer with Linux. You want to find your documents, pictures, and other files. To do this, you need to learn how to move around the computer's file system. This is like walking through rooms in a house to find what you need.
🎯 Goal: Learn how to navigate the Linux file system using basic commands. You will practice moving between folders, checking where you are, and listing files. This is the first and most important skill to use the command line effectively.
📋 What You'll Learn
Create a variable called current_path that stores the current directory path.
Create a variable called home_path that stores the path to the home directory.
Use the cd command to change directories to the home directory stored in home_path.
Use the ls command to list files in the current directory.
Print the current directory path stored in current_path.
💡 Why This Matters
🌍 Real World
Navigating the file system is like walking through folders on your computer. It helps you find files and run programs easily.
💼 Career
Every job that uses Linux or command line tools requires knowing how to move around the file system quickly and confidently.
Progress0 / 4 steps
1
Set up current directory path
Create a variable called current_path and set it to the output of the pwd command, which shows the current directory path.
Linux CLI
Hint
Use $(pwd) to get the current directory path and assign it to current_path.
2
Set up home directory path
Create a variable called home_path and set it to the path of the home directory using ~.
Linux CLI
Hint
The home directory can be represented by ~. Assign it to home_path.
3
Change directory to home
Use the cd command with the variable home_path to change the current directory to the home directory.
Linux CLI
Hint
Use cd "$home_path" to move to the home directory stored in home_path.
4
List files and print current directory
Use the ls command to list files in the current directory. Then, update current_path with the new directory path using pwd and print it using echo.
Linux CLI
Hint
Use ls to see files, then current_path=$(pwd) to update the path, and echo "$current_path" to print it.
Practice
(1/5)
1. Why is file system navigation considered the first skill to learn in Linux command line?
easy
A. Because it automatically fixes file errors.
B. Because it allows you to install software.
C. Because it lets you change system settings directly.
D. Because it helps you find and manage files easily.
Solution
Step 1: Understand the purpose of navigation commands
Commands like cd, ls, and pwd help you move around and see files and folders.
Step 2: Recognize the importance of managing files
Being able to find and organize files is essential before doing other tasks like installing software or changing settings.
Final Answer:
Because it helps you find and manage files easily. -> Option D
Quick Check:
Navigation = Manage files easily [OK]
Hint: Remember: navigation = finding and managing files [OK]
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.