A-Z Popular Blog Study Guide Search »
Related Guides
Information Technology


It Management

Systems Technology

Information Security

Technology Management


Technology Culture

Artificial Intelligence

Low Technology



23 Useful Ls Commands in Linux

The command ls, short for list, is a tool for listing the contents of directories in linux. This command accepts a large number of arguments and can work with other commands in a variety of ways. Most of these possibilities aren't very interesting and are seldom used. The ls commands below are powerful, useful or potentially useful in rare situations.


Variations of the ls command that you may end up using over and over because they are applicable to common tasks.

ls -altr

List all files including hidden files, show a detailed view and sort by modification time with newest last. This is greedy because it shows all files and details. It is lazy because it shows the latest files at the bottom where the listing stops scrolling. This minimizes the chance you'll need to scroll up. If you only remember one variation of the ls command this is a good choice.

ls -alSr

Sort by file size with the biggest files last. This can be used to display the smallest files last by removing the -r at the end.

ls -alt | more

Show a detailed view with newest files first and show only one page of results at a time. This pipes the results of the ls to a command called more that breaks output into pages. The normal way to page down is to hit the space bar. This command gets annoying fast if you ls a directory with thousands of files that corresponds to hundreds of screens. This can normally be interrupted with control-c.

ls -1 | wc -l

Count the number of files and directories. The command ls -1 lists the contents of a directory in a single column. The command wc, short for word count, is a tool for counting newline, word, and byte count. The parameter -l asks for a line count which counts the number of files and directories as they have been formatted into a single column.

Obvious But Important

A few pointers that will be obvious to intermediate users of linux.


There is nothing wrong with the default behavior of ls as it lists file and directory names neatly in multiple columns with no details. This has high information density.

ls /tmp /usr

You can pass ls a list of directories to list.

ls ../..

This syntax lists two directories up from your current working directory.

Potentially Useful

A list of common arguments for the ls command and other useful syntax.


Show hidden files.


Show a detailed listing that includes file permissions, owner, group, size, date and file name.


The -h argument is human readable. This does nothing on its own but works with any argument that displays file sizes to show sizes in gigabytes, megabytes and kilobytes as opposed to bytes that are often a long incomprehensible number.


Sort by modification time in ascending order. If you remove the -r, ls will sort in descending order. The -r stands for reverse.


Display allocated size in a human readable format. The argument -s is for size.


Sort by file size. This is easy to confuse with the command above. Unfortunately, linux often includes case sensitive syntax that represents a type of latent human error. By default, -S sorts in descending order. This can be reversed with -Sr.


This argument accepts a pattern and then ignores anything that matches this pattern in the listing. This is useful when you have a directory filled with one type of file but you want to see everything else. For example, ls -I *.jpg will ignore any .jpg files.


The ls command allows filters based on file or directory name. These filters can contain wildcards with the most commonly used wildcard being an asterisk that simply matches any text or empty space. The following are examples of filters for the ls command. It should be noted that the ls command accepts several wildcards that can perform complex filters. However, the simple filters below are far more commonly used.

ls me.jpg

Only list the file me.jpg

ls *.jpg

List any file that ends in .jpg

ls *me*

List any file that contains the text "me" in its name.

ls me*

List any file with a name that begins "me"

Rarely Useful

Arguments for ls that are rarely used either because they do something obscure or offer functionality that is better served by other commands.


List the index number of each file. These are a unique id associated with each file that are useful in unusual circumstances. For example, if you have trouble deleting a file with a problematic file name, it is possible to delete the file by index number using the find command.


Recursively list all subdirectories and their files. At first, this would appear to be a powerful feature. However, its functionality is weak in comparison to the command find and is therefore mostly unused.


Displays a slash at the end of directory names to make it easier to tell the difference between files and directories. Many terminal emulators color code things so that directories appear in a different color from files. As such, this is rarely used.


Display the user and group that own each file and directory as an id (UID and GID).


Display non-printable file name characters as "?" This is only useful when you are trying to debug a problem with a strange character in a file name. This is a reasonably common type of problem in linux because there are virtually no restrictions on the types of characters that can be used in a filename but many of these characters do not print properly by default in terminal emulators. This means that when you cut and paste file names to a command, they often do not match the file's real name.


See the man pages for ls for rare and unusual ls arguments.
Overview: ls
A tool for listing the contents of directories in linux.
Related Concepts

Linux Commands

This is the complete list of articles we have written about linux commands.
If you enjoyed this page, please consider bookmarking Simplicable.

Linux Commands

A list of unusually useful linux commands with brief explanations.

Linux Processes

The basic types of linux process.


A list of useful shutdown, halt, reboot and power-off commands for linux.


A list of xargs commands for linux you might actually use.

Application Server

An overview of application server with examples.


The definition of transcoding with examples.

Static Content

The definition of static content with examples.

Dynamic Content

The definition of dynamic content with examples.

Computer Science Examples

The definition of computer science with examples.

Command Prompt

The definition of command prompt with examples.
The most popular articles on Simplicable in the past day.

New Articles

Recent posts or updates on Simplicable.
Site Map