Master the ls Command | Listing Files & Directories on Mac/Linux Terminal
Video: Master the ls Command | Listing Files & Directories on Mac/Linux Terminal by Taught by Celeste AI - AI Coding Coach
Watch full page →Master the ls Command | Listing Files & Directories on Mac/Linux Terminal
The ls command is a fundamental tool for navigating and managing files in Mac and Linux terminals. This guide covers how to list files and directories with detailed information, reveal hidden files, display human-readable file sizes, and sort listings by time or size. Combining these options helps you efficiently explore and organize your file system.
Code
# Basic listing of files and directories
ls
# Long format listing showing permissions, ownership, size (in bytes), and modification date
ls -l
# Show all files including hidden ones (files starting with .)
ls -a
# Long format with human-readable file sizes (KB, MB, GB)
ls -lh
# Combine to show all files in long format with human-readable sizes
ls -lah
# Sort files by modification time, newest first
ls -lt
# Sort files by size, largest first
ls -lS
# Recursive listing of all files in current directory and subdirectories
ls -lR
# Combine options: long format, human-readable sizes, sorted by time, recursive
ls -lhtR
Key Points
- The basic
lscommand lists files and directories in the current location. ls -lprovides detailed information including permissions, ownership, size, and modification date.- Use
ls -ato reveal hidden files, which often include important configuration files. ls -hmakes file sizes human-readable, showing KB, MB, or GB instead of bytes.- Sorting and recursive options like
-t,-S, and-Rhelp organize and explore files effectively.