Tutorials : How to Use the ls Command in Linux: A Practical Guide for Beginners
How to Use the ls Command in Linux: A Practical Guide for Beginners
When you first open the Linux terminal, your immediate instinct is to see what files and folders are inside your current directory. To do that, you use the ls (list) command.
While it might seem like a basic tool, ls hides a variety of powerful options (flags) that can make your life as a developer, sysadmin, or casual user much easier. In this guide, we will explore the most useful ways to use the ls command in your daily workflow.
1. The Basic Command
If you type the command by itself, Linux will display the names of the files and directories in your current location, but without any extra details (like file sizes or permissions):
ls
2. Display Detailed Information (The Long Listing Format)
The most popular option to use is -l. This changes the simple list into a detailed table where you can view file permissions, ownership, file size in bytes, and the date and time of the last modification:
ls -l
3. Make File Sizes Human-Readable
By default, the -l flag displays file sizes in bytes, which can be hard to read for large files. Adding the -h flag converts those numbers into Kilobytes (K), Megabytes (M), or Gigabytes (G):
ls -lh
4. Reveal Hidden Files
In Linux, any file or folder that starts with a dot (such as .bashrc or .config) is automatically hidden from the standard view. To see them, use the -a (all) flag:
ls -a
💡 Pro-Tip: Combine Flags for Ultimate Power
You can string these options together into one single, powerful command:
Bashls -lahThis shows absolutely every file (including hidden ones) in a clean, detailed, and human-readable format.
5. Sort Files by Time and Date
If you are looking at a crowded directory and want to find your most recently modified files (like recent downloads or log files) instantly, add the -t flag:
ls -lt
Troubleshooting: Common Errors
What does "ls: cannot open directory... Permission denied" mean?
If you see this error, it means the directory you are trying to look into belongs to the system administrator (root) or another user, and your current account doesn't have reading permissions.
The Fix: Run the command with administrator privileges using
sudo:Bashsudo ls -lah /path/to/folder
🎁 Master the Linux Terminal from Scratch!
The ls command is just the tip of the iceberg. If you want to master navigating the command line like a professional, manage file permissions without anxiety, and learn the top 50 commands you actually need, I've got you covered.
I have compiled all of these shortcuts into a clean Linux Commands Cheat Sheet PDF that you can keep open on your second screen while you practice.

Comments
Post a Comment