Master the Linux ls Command: 15 Essential Options Explained
This guide walks you through the most useful ls command options in Linux, from basic file listings to recursive directory trees, hidden files, human‑readable sizes, sorting by time or size, displaying inode numbers, version info, and alias usage, all illustrated with clear examples.
The ls command is one of the most frequently used commands in Linux. This article discusses basic ls usage and covers a wide range of options.
1. List files without any options
Running ls without options lists files and directories bare, without showing file type, size, modification date, permissions, or links.
2. List files with the -l option
ls -l(the letter "l", not the number "1") shows whether each entry is a file or directory, its size, modification date and time, name, owner, and permissions.
3. Show hidden files
Use ls -a to list all files, including those whose names start with a dot.
4. Human‑readable sizes with -lh
Combine -l and -h to display sizes in a human‑readable format.
5. Append a slash to directories with -F
The -F option adds a trailing "/" to directory names.
6. Reverse order with -r
ls -rdisplays files and directories in reverse order.
7. Recursive listing with -R
ls -Rlists a full directory tree recursively.
8. Sort by modification time (newest first) with -lt or -ltr
The -lt (or -ltr for reverse) option sorts entries by latest modification time.
9. Sort by file size with -lS
The -lS option lists files from largest to smallest.
10. Show inode numbers with -i
Adding -i displays the inode number of each file or directory.
11. Show the ls version
Use ls --version to view the command’s version information.
12. Display the help page
Run ls --help to list all available options and their descriptions.
13. List directory information
ls -l /tmplists files in /tmp; adding -d shows only the directory entry itself.
14. Show UID and GID with -n
ls -ndisplays numeric user IDs (UID) and group IDs (GID) for files and directories.
15. Create an alias for ls
Define an alias such as alias ls='ls -l' so that invoking ls automatically uses the -l option.
Use alias without arguments to list all current aliases, and unalias to remove an alias.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
