0
0
Linux CLIscripting~20 mins

ls (list files and directories) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ls Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of ls -l in a directory with one file named file.txt?
You run the command ls -l in a directory containing a single file named file.txt. What will the output look like?
Linux CLI
ls -l
A
total 0
-rw-r--r-- 1 user user 0 Apr 27 12:00 file.txt
B-rw-r--r-- 1 user user 0 Apr 27 12:00 file.txt
C
total 1
-rw-r--r-- 1 user user 0 Apr 27 12:00 file.txt
Dfile.txt
Attempts:
2 left
💡 Hint
The -l option shows detailed info including permissions, owner, size, and date.
💻 Command Output
intermediate
2:00remaining
What does ls -a show in a directory with files file1, .hidden?
You run ls -a in a directory containing two files: file1 and .hidden. What will the output be?
Linux CLI
ls -a
Afile1
Bfile1 .hidden
C.hidden
D. .. file1 .hidden
Attempts:
2 left
💡 Hint
The -a option shows all files, including hidden and special entries.
📝 Syntax
advanced
2:00remaining
Which ls command lists files sorted by modification time, newest first?
You want to list files sorted by modification time, newest first. Which command is correct?
Als -ltr
Bls -lt
Cls -ltu
Dls -lS
Attempts:
2 left
💡 Hint
The -t option sorts by modification time, -r reverses order.
🔧 Debug
advanced
2:00remaining
Why does ls -l /nonexistent produce an error?
You run ls -l /nonexistent but get an error message. What is the reason?
AThe -l option is invalid with absolute paths
BYou need root permissions to list /nonexistent
CThe directory /nonexistent does not exist
DThe command requires a trailing slash on directories
Attempts:
2 left
💡 Hint
Check if the directory exists before listing.
🚀 Application
expert
2:00remaining
How to list only directories in current folder using ls and shell features?
You want to list only directories (not files) in the current folder using ls combined with shell commands. Which command achieves this?
Als -d */
Bls -l | grep '^d'
Cls -a | grep -v '^-'
Dls -F | grep '/'
Attempts:
2 left
💡 Hint
The -d option lists directories themselves, and */ matches directories.