
Part one in the Linux Command Series
Published on May 23, 2026 by Mike Chilson
Commands Bash Linux Tutorial
4 min READ
The ls command is one of the most fundamental and frequently used commands in Linux and Unix-like operating systems. It stands for “list” and is used to display the contents of a directory. This tutorial covers basic usage, advanced options, and professional tips for mastering ls.
Listing Files and Directories
lsListing with Details
-l option for a long listing format that includes permissions, owner, size, and modification time: ls -lListing Hidden Files
.). Use the -a option to show them: ls -als -la or ls -alListing Specific Directory
ls /path/to/directoryls /home/user/DocumentsHuman-Readable Sizes
-h with -l to show file sizes in human-readable format (KB, MB, etc.): ls -lhUsing Wildcards
Wildcards are powerful pattern-matching tools that allow you to list directories and files selectively without typing every name. They are especially useful when working with large directories or groups of files.
| Wildcard | Description | Example |
|---|---|---|
* | Matches any number of characters | ls *.txt |
? | Matches exactly one character | ls report?.pdf |
[] | Matches any character in the set | ls file[1-5].txt |
Sorting Options
ls -lSls -lt-r, e.g., `ls -ltr (oldest first)Recursive Listing
ls -RFile Type Indicators
ls -FColorized Output
ls --color=autols to ls --color=autoIgnoring Patterns
ls --ignore=\*.tmpCombining Options
ls -lathr This shows all files (-a), long format (-l), human-readable sizes (-h), sorted by time (-t), reversed (-r)Setting Default ls Behavior in Login Scripts
alias ls='ls --color=auto -h' (can be ls with any parameters)alias ll='ls -lh' or alias la='ls -lah'source ~/.bashrcPiping ls Output to Other Commands
| symbol connects the standard output (stdout) of the left command to the standard input (stdin) of the right command. This enables powerful command chaining without saving intermediate results to files.Examples with grep
ls | grep reportls | grep -i reportls -l | grep '\.txt$'ls | wc -lls -lS | head -n 10ls -l | lessAdditional Pro Tips
ls -1 to list one file per line (useful for scripting).ls -ils -d $PWD/\*ls "$DIR"find instead of ls -RMastering the ls command significantly improves your efficiency on the Linux command line. Practice these options in your terminal to become comfortable with them. Combine ls with other commands using pipes for even more powerful workflows. Don’t forget, all this information can be found in the ls man page man ls.
Stay tuned for more tutorials.