0
0
Linux CLIscripting~5 mins

ls options (-l, -a, -h, -R) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
The ls command shows files and folders in a directory. Using options like -l, -a, -h, and -R helps you see more details, hidden files, human-readable sizes, and contents of subfolders.
When you want to see detailed information about files like size, permissions, and modification date.
When you need to find hidden files that start with a dot in a folder.
When you want file sizes shown in easy-to-read units like KB or MB instead of bytes.
When you want to list all files in a folder and all its subfolders recursively.
Commands
This command lists files with detailed info like permissions, owner, size, and modification date.
Terminal
ls -l
Expected OutputExpected
total 12 -rw-r--r-- 1 user user 123 Apr 10 10:00 file1.txt -rwxr-xr-x 1 user user 4096 Apr 9 09:30 script.sh drwxr-xr-x 2 user user 4096 Apr 8 08:20 folder
-l - Show detailed file information
This command shows all files including hidden ones that start with a dot.
Terminal
ls -a
Expected OutputExpected
. .. .hiddenfile file1.txt script.sh folder
-a - Show hidden files
This command lists files with details and shows sizes in human-readable format like KB or MB.
Terminal
ls -lh
Expected OutputExpected
total 12K -rw-r--r-- 1 user user 123 Apr 10 10:00 file1.txt -rwxr-xr-x 1 user user 4.0K Apr 9 09:30 script.sh drwxr-xr-x 2 user user 4.0K Apr 8 08:20 folder
-l - Show detailed file information
-h - Show sizes in human-readable format
This command lists all files in the current folder and all subfolders recursively.
Terminal
ls -R
Expected OutputExpected
.: file1.txt script.sh folder ./folder: inside.txt
-R - List directories recursively
Key Concept

If you remember nothing else, remember: combining ls options lets you see exactly what files exist, their details, hidden files, and folder contents inside folders.

Common Mistakes
Using ls without -a and missing hidden files.
Hidden files starting with a dot won’t show up, so you might miss important config files.
Always add -a if you want to see all files including hidden ones.
Using ls -l without -h and seeing large numbers in bytes.
File sizes are hard to read because they show raw bytes.
Add -h to ls -l to see sizes in KB, MB, etc.
Expecting ls -R to show hidden files inside subfolders without -a.
ls -R alone won’t show hidden files in subfolders.
Combine -a with -R as ls -aR to see all files recursively.
Summary
ls -l shows detailed info about files like size and permissions.
ls -a shows hidden files that start with a dot.
ls -h makes file sizes easy to read by using KB, MB, etc.
ls -R lists all files inside folders and their subfolders.