Master the Linux ‘ls’ Command: 20 Essential Options Explained
This guide introduces the Linux ls command, explains its default behavior, and provides detailed examples of twenty useful options—including long listings, human‑readable sizes, sorting, recursive listing, and more—so readers can efficiently list and inspect files and directories.
ls command overview
The ls utility lists files and directories. By default it displays the contents of the current directory, and a wide range of options allow you to customise the output for various tasks.
Basic usage
lsLong listing format
ls -lThe long format shows several columns:
File type and permission bits
Number of hard links
Owner name
Group name
Size in bytes (directories are typically 4096 B)
Modification timestamp
File or directory name
Human‑readable sizes
ls -lhThe -h flag prints sizes using KiB, MiB, etc., making them easier to read.
Sort by size
ls -lhSThe -S option sorts entries from largest to smallest.
Specify block size
ls -l --block-size=MUse --block-size=SIZE (e.g., M for megabytes) to change the unit used for the size column.
Show hidden files
ls -aFiles whose names start with a dot ( .) are hidden; -a reveals them.
List only directories
ls -d */The -d flag prevents descending into directories and lists the directory entries themselves.
Omit owner information
ls -gThe -g option hides the owner column.
Omit group information
ls -lGThe capital G flag suppresses the group column.
Numeric UID/GID
ls -nPrint numeric user and group IDs instead of names.
Disable colour output
ls --color=neverSome distributions colourise the output; this option turns colour off.
Print inode numbers
ls -liThe -i flag displays each file’s inode number in the first column.
Append ‘/’ to directories
ls -pThe -p flag adds a trailing slash to directory names.
Reverse sort order
ls -rReverse the default sorting direction.
Recursive listing
ls -RList sub‑directories recursively.
Sort by extension
ls -lX
ls --sort=extensionThe -X or --sort=extension options order files by their suffix.
Sort by modification time
ls -ltThe -t flag sorts entries with the newest files first.
List the home directory
ls ~The tilde ( ~) expands to the current user’s home directory.
List parent directories
ls ../
ls ../../Use .. to refer to the parent directory; multiple components move up further levels.
Show version information
ls --versionDisplays the version of the ls program.
For a complete reference, consult the manual pages with man ls or ls --help.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
