Master the Linux ls Command - Complete Guide
Video: Master the Linux ls Command - Complete Guide by Taught by Celeste AI - AI Coding Coach
Watch full page →Master the Linux ls Command - Complete Guide
The ls command is the fundamental tool for listing files and directories in Linux. This guide covers everything from basic listings to advanced options like sorting, filtering, and recursive views, helping you explore your file system efficiently.
Code
# Basic listing of files and directories
ls
# Long format listing with detailed info (permissions, owner, size, date)
ls -l
# Show all files including hidden ones (dotfiles)
ls -a
# Combine long format and show hidden files
ls -la
# Human-readable file sizes (KB, MB, GB)
ls -lh
# Sort by modification time (newest first)
ls -lt
# Sort by file size (largest first)
ls -lS
# Reverse the sort order (oldest or smallest first)
ls -ltr
# Recursive listing of all subdirectories and their contents
ls -R
# List directories only, not files
ls -d */
# Filter files by pattern, e.g., show only text files
ls *.txt
# Show inode numbers of files
ls -i
# Show one file per line (useful for scripts or counting)
ls -1
Key Points
lsby itself lists files and directories in the current location.- The
-loption shows detailed information including permissions, ownership, size, and modification date. - Use
-ato reveal hidden files that start with a dot (e.g.,.bashrc). - Sorting options like
-ltand-lShelp you organize files by modification time or size. - Recursive listing with
-Rand directory-only listing with-d */provide powerful ways to explore directory structures.