The ls Command: Listing and Inspecting Files in Linux
Master the ls command to view directory contents and file metadata. Learn essential flags like -l and -a to manage your Linux environment effectively.

Previously in this course, we covered how to move through the file system using Navigating the File System: A Linux Command Line Guide and how to handle Mastering Absolute and Relative Paths in Linux. Now that you can get where you need to go, this lesson adds the ability to see exactly what’s waiting for you once you arrive.
In Linux, everything is a file. Whether it’s a configuration script for your web server or a system log, you need to be able to inspect these files to understand their properties.
The ls Command: Your Window into Directories
The ls command is the primary tool for listing directory contents. When you run ls by itself, it provides a simple, alphabetical list of files and directories in your current location. While useful for a quick glance, it hides the details that developers need to manage production environments.
To get the visibility required for professional work, we use "flags." Flags are optional parameters that modify the behavior of a command.
Uncovering Hidden Files with -a
Linux hides configuration files—files that usually start with a dot (.), like .bashrc or .gitignore—to keep your workspace clean. To see them, use the -a (all) flag:
Bashls -a
If you don't use this flag, those critical hidden files remain invisible, which is a common source of confusion when you are looking for configuration files that you know exist.
Inspecting File Metadata with -l
The most powerful tool in your listing arsenal is the -l (long format) flag. It displays detailed file metadata, such as permissions, ownership, size, and the last modification time.
Bashls -l
When you run this, you'll see output structured like this:
| Field | Description |
|---|---|
drwxr-xr-x | File type and permissions |
2 | Number of links |
root | Owner |
root | Group |
4096 | Size in bytes |
Oct 24 10:00 | Modification time |
etc | File/Directory name |
The first character indicates the type: d for a directory, - for a regular file, and l for a symbolic link.
Worked Example: Combining Flags

In a real-world scenario—like inspecting your future web server's /var/www directory—you rarely use just one flag. Combining them is standard practice. To see all files (including hidden ones) in long format, use:
Bashls -la
This command provides the "full picture." It allows you to verify if a file is owned by the correct user, check if a directory has the right execution permissions, and see how much space a log file is consuming.
Hands-on Exercise
- Open your terminal.
- Navigate to your home directory using
cd ~. - Run
ls -lto see your files. Look for a directory or file and note its size in bytes. - Run
ls -laand compare the output. Can you spot any files that were invisible before? - Identify one directory (starting with
d) and one file (starting with-).
Common Pitfalls
- Assuming -l shows everything: Remember that
-ldoes not show hidden files by default. Always use-laif you suspect you are missing files. - Misinterpreting File Size: The default
ls -loutput shows sizes in bytes. For large files, this is hard to read. Developers often add the-h(human-readable) flag to convert bytes into KB, MB, or GB:ls -lah. - Ignoring the Path: You can run
lson any directory without moving into it. Instead ofcding into a folder, just runls -l /var/logto inspect logs from anywhere.
Frequently Asked Questions
What does the first character in the ls -l output mean?
It denotes the file type. d is a directory, - is a standard file, and l is a symbolic link (a shortcut).
Why is my file size showing as 4096? In Linux, 4096 bytes is the standard size for a directory's metadata block. It doesn't mean the directory is "empty" or "full," just that the file system has allocated that space to track the contents of that folder.
Can I sort files by size?
Yes, you can use the -S flag (ls -lS) to sort files by size, with the largest files appearing first.
Recap

You now know how to use the ls command to peek into your directories. By mastering the -l flag for metadata and -a for hidden files, you are ready to start managing the file structure of your hardened web server.
Up next: We will begin our project by setting up the directory structure for your web server in "Project Kickoff: Provisioning Web Server Directories."
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Custom Email & File Storage System on Cloudflare (Google Workspace Alternative)
Your own private email + file storage suite on your domain — unlimited mailboxes, no per-seat fees. A self-owned Google Workspace alternative for a flat ~$5/month.

