Linux ls Command
The ls command is one of the most frequently used Linux commands.
It is used to:
- List files
- List directories
- View hidden files
- Check permissions
- View file sizes
- Display inode numbers
- Sort files
As a Linux administrator, you will use ls hundreds of times every day.
What does LS mean?
ls stands for:
List
Syntax
ls [OPTIONS] [FILE/DIRECTORY]
Basic Usage
ls
Example:
Documents Downloads Pictures Music Videos
Listing Specific Directory
ls /etc
ls /var/log
ls /home
Command Options
| Flag | Description |
|---|---|
-a | Show hidden files |
-l | Long listing format |
-h | Human readable sizes |
-la | Long listing + hidden files |
-R | Recursive listing |
-t | Sort by modification time |
-S | Sort by size |
-r | Reverse order |
-i | Show inode numbers |
-d | Show directory itself |
-F | Classify file types |
--color | Colored output |
--help | Display help |
ls -a
Shows hidden files.
Linux hidden files begin with:
.
Example:
ls -a
Output:
.
..
.bashrc
.profile
.ssh
Documents
Downloads
Why Hidden Files Matter
Hidden files usually contain:
- User configurations
- Git settings
- SSH keys
- Application settings
Examples:
.bashrc
.gitconfig
.ssh
.env
ls -l
Displays detailed information.
Example:
ls -l
Output:
drwxr-xr-x 2 aayan users 4096 Jul 14 Documents
-rw-r--r-- 1 aayan users 1542 Jul 14 notes.txt
Understanding ls -l
Example:
drwxr-xr-x
First Character
| Symbol | Meaning |
|---|---|
d | Directory |
- | Regular File |
l | Symbolic Link |
c | Character Device |
b | Block Device |
Permissions
rwxr-xr-x
Breakdown:
rwx → Owner
r-x → Group
r-x → Others
Link Count
2
Number of hard links.
Owner
aayan
Group
users
File Size
4096
Measured in bytes.
Date
Jul 14
Last modification date.
Filename
Documents
ls -h
Makes sizes easier to read.
Example:
ls -lh
Output:
1.2K file.txt
500M backup.zip
2.4G world.tar.gz
Without:
ls -l
Output:
2534763492 world.tar.gz
ls -la
Most commonly used option.
Example:
ls -la
Shows:
✅ Hidden files
✅ Permissions
✅ Ownership
✅ Sizes
ls -R
Recursive listing.
Lists all files inside subdirectories.
Example:
ls -R
Output:
Projects:
website
server
website:
index.php
style.css
ls -t
Sort by modification time.
Newest files appear first.
Example:
ls -lt
Useful for:
- Logs
- Server debugging
- Development
ls -S
Sort by file size.
Example:
ls -lhS
Largest files appear first.
Useful for:
- Finding huge backups
- Identifying large world folders
ls -r
Reverse sorting.
Example:
ls -lr
ls -i
Display inode numbers.
Example:
ls -i
Output:
45123 file.txt
45124 backup.zip
Useful for:
- Filesystem debugging
- Hard links
- Forensics
ls -d
Shows directory itself.
Example:
ls -ld /etc
Output:
drwxr-xr-x root root /etc
ls -F
Classifies file types.
Example:
ls -F
Output:
Documents/
script.sh*
shortcut@
Meaning:
| Symbol | Meaning |
|---|---|
/ | Directory |
* | Executable |
@ | Symbolic Link |
Combining Flags
Linux allows multiple options.
Example:
ls -lah
Equivalent:
ls -l -a -h
Common Combinations
Detailed Listing
ls -la
Human Readable
ls -lah
Sort by Time
ls -lht
Sort by Size
ls -lhS
Recursive Listing
ls -laR
Real Server Examples
PocketMine Plugins
ls -lah plugins/
Output:
BedWars.phar
EconomyAPI.phar
ScoreHud.phar
World Sizes
ls -lhS worlds/
Find the largest worlds.
Logs
ls -lt logs/
Newest logs appear first.
Website Hosting
ls -lah /var/www/html
Verify website files.
PHP Configuration
ls /etc/php
Nginx Configuration
ls /etc/nginx
Ethical Hacking Examples
View wordlists:
ls /usr/share/wordlists
View binaries:
ls /usr/bin
Common Mistakes
Hidden Files Not Appearing
Wrong:
ls
Correct:
ls -a
Sizes Hard to Read
Wrong:
ls -l
Correct:
ls -lh
Forgetting Permissions
Wrong:
ls
Correct:
ls -l
Interview Questions
What does ls do?
Lists files and directories.
What does ls -a show?
Hidden files.
What does ls -lh do?
Displays human readable file sizes.
What does ls -i display?
Inode numbers.
Difference between ls and ls -l?
ls:
Only filenames.
ls -l:
Detailed information.
Exercises
Exercise 1
Show hidden files.
ls -a
Exercise 2
Display detailed listing.
ls -l
Exercise 3
Display human readable sizes.
ls -lh
Exercise 4
Sort by modification time.
ls -lt
Exercise 5
Sort by file size.
ls -lhS
Practice Lab
Create:
mkdir LinuxLab
cd LinuxLab
touch file1.txt
touch file2.txt
mkdir Projects
mkdir Scripts
Practice:
ls
ls -l
ls -la
ls -lah
ls -R
ls -lhS
ls -i
Command Summary
| Command | Purpose |
|---|---|
ls | List files |
ls -a | Hidden files |
ls -l | Detailed information |
ls -lh | Human readable sizes |
ls -la | Detailed + hidden |
ls -R | Recursive listing |
ls -lt | Sort by time |
ls -lhS | Sort by size |
ls -i | Inode numbers |
Key Takeaways
✅ ls is one of the most important Linux commands.
✅ Used to inspect files and directories.
✅ Supports numerous options.
✅ Essential for Linux administration, ethical hacking and server management.
Next Chapter
➡ Linux cd Command
Learn how to navigate through the Linux filesystem.