Bird
Raised Fist0
Linux CLIscripting~10 mins

ls options (-l, -a, -h, -R) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - ls options (-l, -a, -h, -R)
Start: ls command
↓
Check options
↓
List detailed
↓
Combine effects
↓
Display output
↓
End
The ls command checks which options are used (-l, -a, -h, -R), applies their effects, combines them if multiple, then shows the output.
Execution Sample
Linux CLI
ls -l -a -h -R
Lists all files and folders with details, human-readable sizes, including hidden files, recursively.
Execution Table
StepOption CheckedEffectOutput ExampleNotes
1-lShow detailed info (permissions, owner, size, date)-rw-r--r-- 1 user group 1234 Apr 27 10:00 file.txtLists files with details
2-aInclude hidden files (names starting with .).bashrc .file.txt folderShows all files including hidden
3-hShow sizes in human-readable format (K, M)1.2K, 3.4MMakes sizes easy to read
4-RList directories recursivelyfolder: file1 subfolder: file2Shows contents of subfolders too
5Combine allDetailed + all files + human sizes + recursiveFull detailed recursive list including hidden files with human sizesAll options work together
6EndCommand finishesOutput shown on screen
💡 All options processed, output displayed, command ends
Variable Tracker
VariableStartAfter -lAfter -aAfter -hAfter -RFinal
file_listvisible files onlydetailed info addedhidden files includedsizes in human-readable formatrecursive folders includedfull detailed recursive list with hidden files and human sizes
Key Moments - 3 Insights
Why do hidden files only appear after using -a?
Because by default ls hides files starting with '.', and -a tells ls to include them. See execution_table row 2 where -a adds hidden files.
How does -h change the size display?
It converts raw byte counts into human-friendly units like K (kilobytes) or M (megabytes), as shown in execution_table row 3.
What does -R do differently compared to no option?
-R makes ls list all subdirectories recursively, not just the current folder. See execution_table row 4 for example output.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what effect does the -a option have on the file list?
AIncludes hidden files starting with '.'
BShows file sizes in bytes
CLists files recursively
DShows detailed file permissions
💡 Hint
Check execution_table row 2 for the effect of -a
At which step does ls start showing sizes in human-readable format?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at execution_table row 3 describing -h option
If you remove the -R option, what changes in the output?
AHidden files will not show
BSizes will not be human-readable
CSubdirectories will not be listed recursively
DFile details will not show
💡 Hint
See execution_table row 4 about -R recursive listing
Concept Snapshot
ls command options:
-l : show detailed info (permissions, owner, size, date)
-a : include hidden files (names starting with '.')
-h : show sizes in human-readable units (K, M)
-R : list directories recursively
Combine options to customize output
Full Transcript
The ls command lists files and folders. Using options changes what you see. The -l option shows detailed info like permissions and size. The -a option includes hidden files that start with a dot. The -h option makes file sizes easier to read by using units like K or M. The -R option lists all folders inside folders, showing everything recursively. You can use these options together to get detailed, complete, and easy-to-read file lists. The command checks each option, applies its effect, combines them, then shows the final output.

Practice

(1/5)
1. What does the ls -a command do in Linux?
easy
A. Shows all files including hidden ones
B. Lists files with detailed information
C. Displays file sizes in human-readable format
D. Lists files recursively in subdirectories

Solution

  1. Step 1: Understand the -a option

    The -a option in ls shows all files, including hidden files that start with a dot.
  2. Step 2: Compare with other options

    Other options like -l show details, -h shows sizes human-readable, and -R lists recursively.
  3. Final Answer:

    Shows all files including hidden ones -> Option A
  4. Quick Check:

    -a means show hidden files [OK]
Hint: Remember: 'a' for all files including hidden [OK]
Common Mistakes:
  • Confusing -a with -l for detailed info
  • Thinking -a shows sizes in human format
  • Assuming -a lists files recursively
2. Which of the following is the correct syntax to list files with detailed info and human-readable sizes?
easy
A. ls -la
B. ls -lR
C. ls -h -a
D. ls -lh

Solution

  1. Step 1: Combine options for detailed and human-readable

    The -l option shows detailed info, and -h makes sizes human-readable. Together, ls -lh is correct.
  2. Step 2: Check option order and other choices

    A (ls -la) shows detailed info including hidden files but misses human-readable sizes. C (ls -h -a) misses detailed info. D (ls -lR) lists recursively, not human-readable sizes.
  3. Final Answer:

    ls -lh -> Option D
  4. Quick Check:

    -l + -h = detailed + human sizes [OK]
Hint: Use -l and -h together for details and friendly sizes [OK]
Common Mistakes:
  • Mixing up option order and meaning
  • Using -h without -l for details
  • Confusing -R with -h
3. What will be the output of ls -lR in a directory with two subfolders, each containing files?
medium
A. Lists files in current directory only
B. Shows file sizes in human-readable format
C. Lists files with details in current and all subdirectories
D. Lists hidden files only

Solution

  1. Step 1: Understand -lR options

    -l lists files with details, and -R lists recursively through all subdirectories.
  2. Step 2: Predict output behavior

    The command will show detailed info for files in the current directory and all files in subfolders recursively.
  3. Final Answer:

    Lists files with details in current and all subdirectories -> Option C
  4. Quick Check:

    -lR = detailed + recursive listing [OK]
Hint: Remember -R means recursive, -l means detailed [OK]
Common Mistakes:
  • Thinking -R lists hidden files only
  • Assuming -lR shows human-readable sizes
  • Believing it lists only current directory
4. You ran ls hR but got an error: "ls: cannot access 'hR': No such file or directory". What is the likely cause?
medium
A. Options must be combined without spaces
B. You typed options together without a dash
C. Options order is incorrect
D. You used uppercase letters instead of lowercase

Solution

  1. Step 1: Analyze the error message

    The error "ls: cannot access 'hR': No such file or directory" suggests the shell interpreted 'hR' as a file or directory name.
  2. Step 2: Identify correct option syntax

    Options must be preceded by a dash and can be combined like -hR. Typing ls hR without dash causes the shell to treat 'hR' as a filename.
  3. Final Answer:

    You typed options together without a dash -> Option B
  4. Quick Check:

    Options need dash prefix [OK]
Hint: Always prefix options with a dash (-) [OK]
Common Mistakes:
  • Using uppercase instead of lowercase options
  • Putting spaces between dash and options
  • Assuming option order matters
5. You want to list all files including hidden ones, with detailed info and human-readable sizes, recursively through all subdirectories. Which command should you use?
hard
A. ls -alhR
B. ls -lha
C. ls -aRl
D. ls -l -a -h

Solution

  1. Step 1: Identify needed options

    You need -a for hidden files, -l for detailed info, -h for human-readable sizes, and -R for recursive listing.
  2. Step 2: Combine options correctly

    All options can be combined as -alhR. ls -alhR: ls -alhR includes all needed options.
  3. Step 3: Check other options

    B (ls -lha) misses recursive -R. C (ls -aRl) includes all options but order does not matter in Linux, so it is also correct. D (ls -l -a -h) misses recursive -R.
  4. Final Answer:

    ls -alhR -> Option A
  5. Quick Check:

    All needed options combined = ls -alhR [OK]
Hint: Combine all needed options with one dash for full listing [OK]
Common Mistakes:
  • Forgetting -R for recursion
  • Not combining options properly
  • Using options without dash
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard