The ls command lists files and directories in the current folder or a specified path.
Click to reveal answer
beginner
How do you list all files, including hidden ones, using ls?
Use ls -a to show all files, including those starting with a dot (hidden files).
Click to reveal answer
beginner
What does the -l option do with ls?
The -l option shows a detailed list with permissions, owner, size, and modification date.
Click to reveal answer
intermediate
How can you list files sorted by modification time using ls?
Use ls -lt to list files sorted by modification time, newest first.
Click to reveal answer
intermediate
What does ls -R do?
The -R option lists directories and their contents recursively, showing all nested files and folders.
Click to reveal answer
Which ls option shows hidden files?
A-R
B-l
C-t
D-a
✗ Incorrect
The -a option includes hidden files (those starting with a dot).
What does ls -l display?
ADetailed info like permissions and size
BHidden files only
CFiles sorted by size
DOnly file names
✗ Incorrect
-l shows detailed information about files and directories.
How do you list files sorted by modification time, newest first?
Als -R
Bls -lt
Cls -a
Dls -lh
✗ Incorrect
ls -lt sorts files by modification time, newest first.
Which command lists all files and directories inside subfolders too?
Als -R
Bls -a
Cls -l
Dls -t
✗ Incorrect
ls -R lists contents recursively inside all subdirectories.
What does the plain ls command show by default?
AAll files including hidden
BOnly directories
CFiles and directories except hidden files
DDetailed file info
✗ Incorrect
Plain ls lists files and directories except hidden ones.
Explain how to use ls to see detailed info about all files, including hidden ones.
Combine options to get detailed and hidden files listed.
You got /5 concepts.
Describe how to list files recursively in all subdirectories using ls.
Think about how to see inside folders inside folders.
You got /4 concepts.
Practice
(1/5)
1. What does the ls command do in Linux?
easy
A. Creates a new directory
B. Deletes files from the current folder
C. Lists files and directories in the current folder
D. Moves files to another folder
Solution
Step 1: Understand the purpose of ls
The ls command is used to show what files and folders are inside a directory.
Step 2: Identify the correct description
Among the options, only listing files and directories matches what ls does.
Final Answer:
Lists files and directories in the current folder -> Option C
Quick Check:
ls = list files [OK]
Hint: Remember: ls = list files and folders [OK]
Common Mistakes:
Confusing ls with commands like rm or mkdir
Thinking ls deletes or moves files
Assuming ls creates directories
2. Which of these is the correct syntax to list all files including hidden ones in a directory?
easy
A. ls -l
B. ls -r
C. ls -h
D. ls -a
Solution
Step 1: Recall option meanings for ls
-a shows all files including hidden (those starting with a dot).
Step 2: Match option to requirement
Only ls -a lists hidden files; others do different things like long format or reverse order.
Final Answer:
ls -a -> Option D
Quick Check:
-a means all files [OK]
Hint: Use -a to see hidden files starting with . [OK]
Common Mistakes:
Using -l instead of -a to see hidden files
Confusing -r (reverse) with -a
Thinking -h shows hidden files
3. What will be the output of the command ls -l /tmp if the /tmp directory contains two files named file1.txt and file2.log?
medium
A. file1.txt file2.log
B. Detailed list showing permissions, owner, size, and date for file1.txt and file2.log
C. Only hidden files in /tmp
D. An error saying /tmp does not exist
Solution
Step 1: Understand -l option with ls
The -l option shows a detailed list including permissions, owner, size, and modification date.
Step 2: Apply to /tmp directory contents
Since /tmp has two files, the command will show detailed info lines for both files.
Final Answer:
Detailed list showing permissions, owner, size, and date for file1.txt and file2.log -> Option B
Quick Check:
ls -l = detailed list [OK]
Hint: -l means long detailed listing [OK]
Common Mistakes:
Expecting just filenames without details
Thinking it lists only hidden files
Assuming it shows an error if directory exists
4. You run ls -la /home/user but get an error: ls: cannot access '/home/user': No such file or directory. What is the most likely cause?
medium
A. /home/user directory does not exist
B. You forgot to add the -a option
C. You need to run the command as root
D. The ls command is misspelled
Solution
Step 1: Analyze the error message
The error says the directory '/home/user' cannot be accessed because it does not exist.
Step 2: Check other options
Options -a and running as root do not cause this error; misspelling ls would cause a different error.
Final Answer:
/home/user directory does not exist -> Option A
Quick Check:
Directory missing = cannot access error [OK]
Hint: Check if directory exists before blaming options [OK]
Common Mistakes:
Assuming missing -a causes error
Thinking root is always needed
Confusing command misspelling with directory missing
5. You want to list all files in the directory /var/log sorted by modification time, newest first, including hidden files. Which command should you use?
hard
A. ls -lat /var/log
B. ls -ltr /var/log
C. ls -al /var/log
D. ls -lh /var/log
Solution
Step 1: Identify options needed
-a shows hidden files, -t sorts by modification time, newest first, and -l gives detailed listing.
Step 2: Match options to command
Only ls -lat /var/log combines all needed options correctly.
Final Answer:
ls -lat /var/log -> Option A
Quick Check:
-lat = list all, sort by time [OK]
Hint: Use -lat to list all files sorted by time [OK]
Common Mistakes:
Using -ltr which sorts oldest first
Forgetting -a to show hidden files
Using -lh which shows size but not sorting
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.