Linux Curriculum
On this page
- Listing Files
- Essential ls Command Flags
- Anatomy of the Long Listing Output (ls -l)
- Breaking Down Each Column
- High-Frequency DevOps Recipes
- 1. Identify the 10 Largest Files in a Directory
- 2. View Recently Modified Files
- 3. Check Directory Permissions (Not Contents)
- 4. Display Hidden Files and Dotfiles
- 5. Inspect File Inodes
- Modern Linux Alternatives: exa / eza
- Common Pitfalls and Best Practices
- Summary
Listing Files
The ls (list) command is one of the foundational utilities in Linux and Unix-like operating systems. It queries the filesystem directory structure and displays the contents—files, directories, symbolic links, sockets, named pipes, and device nodes—along with their associated metadata (permissions, ownership, file size, timestamps).
In DevOps and cloud engineering, navigating directories and inspecting file attributes via ls is a daily necessity: verifying application deployments, validating configuration permissions in /etc, inspecting log rotations in /var/log, or checking mounted container volumes.
Command Syntax and Anatomy
When run without arguments, ls lists files in the current working directory in alphabetical order, omitting hidden files (files beginning with a dot .).
Essential ls Command Flags
Anatomy of the Long Listing Output (ls -l)
Running ls -la /var/log/nginx produces output similar to this:
Breaking Down Each Column
- File Type & Permissions (10 characters):
1st character: File type indicator:-: Regular filed: Directoryl: Symbolic linkc: Character device (e.g.,/dev/urandom)b: Block device (e.g.,/dev/sda1)s: Unix domain socket (e.g.,/var/run/docker.sock)p: Named pipe (FIFO)
Characters 2–4: User (owner) permissions (rwx= read, write, execute).Characters 5–7: Group permissions (r-x).Characters 8–10: Others/World permissions (r--).
- Hard Link Count: The number of hard links pointing to this inode. For directories, this reflects subdirectories (due to internal
.and..links). - Owner Username: The user account that owns the file (
www-data). - Group Name: The primary group associated with the file (
adm). - File Size: Size formatted in human-readable units (
1.2M) when-his supplied. - Last Modification Timestamp: Date and time when file content was last written.
- File Name: Name of the resource, plus target arrow
->if it is a symbolic link.
High-Frequency DevOps Recipes
1. Identify the 10 Largest Files in a Directory
When troubleshooting disk space exhaustion on a server:
Note: head -n 11 accounts for the total header line plus the top 10 files.
2. View Recently Modified Files
Find what changed on the server within the last few minutes:
Or view in reverse order so the newest file appears at the bottom of your terminal screen:
3. Check Directory Permissions (Not Contents)
Common mistake: running ls -l /var/www/html displays the contents of /var/www/html. To inspect permissions of the directory itself:
4. Display Hidden Files and Dotfiles
Inspect application secrets and version control manifests:
5. Inspect File Inodes
Modern Linux Alternatives: exa / eza
On modern DevOps developer machines and cloud instances, modern replacements like eza (formerly exa) provide color-coded output, Git integration status, and tree views:
However, standard POSIX ls is guaranteed to exist on every minimal Docker image, Alpine container, enterprise RHEL server, and embedded appliance. Mastering standard ls flags is essential for any production engineer.
Common Pitfalls and Best Practices
[!WARNING] Do not parse
lsin shell scripts. Avoid writing:for file in $(ls *.log); do ... done. If filenames contain spaces, newlines, or special characters, shell word-splitting will break your script. Instead, use native globbing:
[!TIP] Add handy aliases to your
~/.bashrcor~/.zshrc:
Summary
lslists directory contents and queries filesystem metadata via POSIX system calls.- The standard daily triage command is
ls -lah(long, all files, human-readable). - To sort chronologically, use
-t(newest first) or-ltr(oldest first, newest at the bottom). - Use
ls -ld <directory>to view permissions of the directory itself rather than its inner contents. - Never parse
lsoutput in automated bash scripts; rely on shell globbing orfind.