Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Bash

How to List Files in Linux: A Comprehensive Guide for Beginners

By Freedom251 Team · · 8 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

The quickest way to list files in Linux is to run ls in a terminal:

ls

That command shows the entries in your current directory, but it hides names beginning with a period and normally does not show details such as permissions or file size. This guide explains the most useful ways to list files, inspect directories, include hidden entries, sort results, search through subdirectories, and avoid common command-line mistakes.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before using ls, check your location

ls without a path lists the directory where your shell is currently located. Use pwd to confirm that location:

pwd
ls

Linux also provides a few useful path shortcuts:

Path Meaning Example
. Current directory ls .
.. Parent directory ls ..
~ Your home directory ls ~

You can give ls either a relative path, such as Documents, or an absolute path, such as /var/log:

#1 Best Overall
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (8) Canvas for Bedroom Living Room Decor 08x12inch(20x30cm) Unframe-style
  • NOTE: All poster prints may vary slightly from what you see on your screen due to the resolution and colour profile of your device. These prints look AMAZING when displayed in a frame or straight on the wall.
  • QUALITY: The poster is printed on canvas. It is waterproof,moisture proof and high tensile strength.The poster has rich printing color and fine texture.
  • DECORATION: TOP MODERN! Really eye-catching! Ideal for all modern graphic & photographic designs. Your wall / room gets very special lightness & beauty.
  • FEATURES: We are good at making canvas posters, making high-quality posters is our pursuit, Different from paper posters, canvas posters have better quality and longer shelf life.
  • If you are not satisfied with our print paintings, please feel free to contact us.
ls Documents
ls /etc
ls /var/log

When you provide a directory, ls lists that directory’s contents. It does not enter the directory or list the directory itself unless you use the -d option.

List hidden files

Linux commonly treats a name as hidden when it begins with a period. Examples include .bashrc, .config, and .ssh. These are not hidden because of a special file extension; the leading period is the convention.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use -a or --all to show every entry:

ls -a

This includes the special entries . and ... In most situations, -A is more convenient because it shows hidden files without those two entries:

ls -A

The options can also be combined with long format:

ls -la
ls -lA

There is an important difference between naming a hidden directory and displaying hidden entries inside it. This lists the explicitly named .config directory:

ls .config

Hidden entries inside that directory are still omitted. To show them, use:

ls -a .config

List files with details using long format

The basic command displays names only. Add -l for long format:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -l

A typical line looks like this:

-rw-r--r-- 1 alice developers 1250 Aug  8 10:30 report.txt

Read the columns from left to right:

  1. Type and permissions: the first character identifies the object type; the remaining characters show permissions.
  2. Hard-link count: the number of hard links to the inode.
  3. Owner: the user who owns the entry.
  4. Group: the group assigned to it.
  5. Size: the logical size in bytes.
  6. Modification time: when the file’s contents were last modified.
  7. Name: the file or directory name.

The first character is not a permission bit. It identifies the object:

Character Object
- Regular file
d Directory
l Symbolic link
c Character device
b Block device
p Named pipe (FIFO)
s Socket

For example, drwxr-xr-x starts with d, so the entry is a directory. The next nine characters describe read, write, and execute permissions for the owner, group, and other users.

Use human-readable file sizes

In long format, sizes are normally shown as bytes. Add -h to make them easier to read:

ls -lh
ls -lah

With GNU ls, -h uses powers of 1024. Thus, a displayed M represents a mebibyte of 1,048,576 bytes. If you specifically want powers of 1000, use the GNU-specific --si option:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -l --si

For most everyday inspection, ls -lah is a useful default: it shows permissions, owners, dates, hidden entries, and readable sizes.

Show directories themselves

Normally, an argument that names a directory causes ls to display that directory’s contents:

ls /var/log

Use -d when you want information about the directory entry itself:

ls -ld /var/log

A common example is listing the directory names in the current directory without opening each one:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -d */

The */ part is expanded by the shell and normally matches visible directories. Shell wildcards do not match names beginning with a period unless you handle those names separately.

Make file types easier to recognize

ls -F appends indicators to names:

ls -F
Indicator Meaning
/ Directory
@ Symbolic link
* Executable regular file
| Named pipe
= Socket

If you only want directories marked, use:

ls -p

Color is a separate display feature. On GNU ls, this command normally enables color only for terminal output:

ls --color=auto

Color should not be treated as reliable data in scripts. Terminal color codes are presentation, not file metadata.

Rank #2
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (9) Canvas for Living Room Bedroom Decor 12x18inch(30x45cm) Unframe-style
  • NOTE: All poster prints may vary slightly from what you see on your screen due to the resolution and colour profile of your device. These prints look AMAZING when displayed in a frame or straight on the wall.
  • QUALITY: The poster is printed on canvas. It is waterproof,moisture proof and high tensile strength.The poster has rich printing color and fine texture.
  • DECORATION: TOP MODERN! Really eye-catching! Ideal for all modern graphic & photographic designs. Your wall / room gets very special lightness & beauty.
  • FEATURES: We are good at making canvas posters, making high-quality posters is our pursuit, Different from paper posters, canvas posters have better quality and longer shelf life.
  • If you are not satisfied with our print paintings, please feel free to contact us.

Sort the listing

GNU ls sorts by name by default, using the current locale’s collation rules. The order can therefore vary between systems or locales.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Command Result
ls -r Reverse the selected order
ls -lt Newest modification time first
ls -ltr Oldest modification time first
ls -lS Largest files first
ls -lSr Smallest files first
ls -lX Sort by file extension
ls -lv Version-aware sorting, such as file2 before file10

The GNU option -U disables sorting and uses the order returned by the directory:

ls -U

This is not creation order. Directory order depends on the filesystem and implementation. GNU ls -f also disables sorting, but unlike -U, it implies -a and includes hidden entries.

Print one entry per line

Interactive ls output is usually arranged in columns. Use -1 when you want one entry per line:

ls -1
ls -1A

When output is redirected or piped, GNU ls normally switches to one name per line automatically. The explicit option is still useful when you want predictable human-readable output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

List subdirectories recursively

Use -R to list a directory and then continue into its subdirectories:

ls -R project/
ls -laR project/

Recursive output can become very large. Avoid casually running ls -R /; it may attempt to traverse a huge portion of the system and will encounter permission errors, mounted filesystems, and other special cases.

For controlled searches, find is usually a better tool because it can restrict depth, type, and name.

Use find for filtered or controlled listings

These commands cover common situations:

Command What it lists
find . Everything below the current directory, recursively
find . -type f Regular files only
find . -type d Directories only
find . -type l Symbolic links only
find . -name '*.pdf' PDF names, case-sensitive
find . -iname '*.pdf' PDF names, case-insensitive
find . -maxdepth 1 The current directory and its immediate entries
find . -mindepth 1 -maxdepth 1 -type f Regular files directly in the current directory

Quote the pattern in -name '*.pdf'. The quotes stop the shell from expanding the wildcard before find receives it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle unusual file names safely

Linux permits spaces, tabs, quotes, backslashes, and even newline characters in a file name. That makes ordinary line-based command output unsuitable for general-purpose scripts.

For a human-readable display, GNU ls provides:

ls -b   # escape nongraphic characters
ls -N   # print names literally
ls -Q   # use double quotes and C-style escapes

Do not parse ordinary ls output in a script. A safer GNU/Linux pipeline uses NUL separators:

find . -type f -print0 | xargs -0 ls -l

Or let find invoke ls directly:

find . -type f -exec ls -l -- {} +

The -- separates options from file operands, which protects against a name beginning with a hyphen. GNU ls --zero is another option for NUL-terminated output, but it is not available in every ls implementation.

Use wildcards correctly

Patterns such as *.txt are expanded by the shell before ls runs:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls *.txt
ls report-*.pdf
ls project/*/

Important consequences:

  • * normally does not match hidden names.
  • A wildcard can match directories as well as regular files.
  • If nothing matches, Bash normally passes the literal pattern to ls, which then reports an error.
  • Quoting the wildcard prevents expansion. ls "*.txt" looks for a literal file named *.txt.

This common command does not list every entry:

ls *

It excludes hidden entries, and if a match is a directory, ls lists that directory’s contents. Use ls -A for hidden entries or ls -d -- * when you want the matched names themselves.

Inspect symbolic links, inodes, and allocated space

To inspect a symbolic link itself, use long format:

ls -l link-name

Output commonly looks like:

lrwxrwxrwx 1 alice alice 11 Aug  8 10:30 link-name -> target-name

A broken symbolic link can still appear in a directory listing, even though commands that follow it may report that its target does not exist.

Use -i to show inode numbers:

ls -i

An inode identifies an object within a particular filesystem; it is not necessarily unique across all mounted filesystems.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use -s to show filesystem blocks allocated to each entry:

ls -s

Allocated blocks are not the same as the logical byte size shown by ls -l. Sparse files are one reason the values can differ.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Graphically show hidden files

In GNOME Files, open the file manager menu and select Show Hidden Files. The shortcut is:

Ctrl+H

This changes visibility in the file manager; it does not delete, rename, or otherwise alter the hidden files. KDE Plasma, Xfce, Cinnamon, MATE, and other desktop environments may use different menu labels or shortcuts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use tree for a visual hierarchy

tree displays directories as a diagram, but it is an optional program rather than a command guaranteed to be installed on every Linux system. On Ubuntu, install it with:

sudo apt install tree

Then run:

tree
tree -a

The -a option includes hidden files and directories. For very large directories, find is generally more flexible because it can limit depth and filter entries.

Useful command combinations

These are practical commands to keep handy:

Goal Command
Basic listing ls
List a specific directory ls /var/log
Show all entries, including . and .. ls -a
Show hidden entries without . and .. ls -A
Detailed listing ls -l
Detailed listing with readable sizes ls -lh
Detailed listing including hidden entries ls -lah
Newest files first ls -lt
Directories only, without opening them ls -d */
One entry per line ls -1
Recursive listing ls -R

Portability and common mistakes

ls is a user-space program, not a feature of the Linux kernel. Many full Linux distributions use GNU Coreutils, while minimal systems may use BusyBox or another implementation. Options can differ.

Check the implementation on the system you are using:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
command -v ls
ls --version
ls --help
man ls

ls --version is supported by GNU ls but may not work with BusyBox or other variants. When writing scripts intended for different systems, prefer documented portable options and verify them on the target environment.

Remember these points:

  • ls lists directory entries of many types, not just regular files.
  • ls -l normally shows modification time, not file creation time.
  • ls -lh uses powers of 1024 with GNU ls; --si uses powers of 1000.
  • ls -U does not mean creation order.
  • A file extension does not determine a Linux file’s type. Use file filename when you need to identify content.
  • Use find, rather than parsing ordinary ls output, when arbitrary file names or scripts are involved.

FAQ

What command lists files in Linux?

Run ls to list the contents of the current directory. Add a path, such as ls /etc, to list another directory.

How do I list hidden files in Linux?

Use ls -a to include hidden files plus the special . and .. entries. Use ls -A to include hidden files without those two entries.

What does ls -l show?

Long format shows the object type and permissions, hard-link count, owner, group, size, modification time, and name.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I list files by date?

Use ls -lt for newest modification times first or ls -ltr for oldest first.

How do I list only files in the current directory?

For regular files directly in the current directory, use find . -mindepth 1 -maxdepth 1 -type f. This avoids descending into subdirectories.

Why does ls show directories’ contents?

When a directory is supplied as an operand, ls normally opens it and lists its contents. Use ls -d directory-name to display the directory entry itself.

Is ls -R safe for listing the whole system?

It can generate an extremely large amount of output and encounter permission errors. Use it on a specific project or directory; use find when you need depth or type filters.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I safely use ls output in a script?

Not for arbitrary file names. Spaces, newlines, tabs, and other characters can make human-oriented output ambiguous. Prefer find -print0 with a NUL-aware tool or find -exec.

The Bottom Line

Start with ls for a quick directory listing, ls -lah when you need details and hidden entries, and ls -lt or ls -lS when sorting matters. Use find for filtered, recursive, or script-friendly work, and verify options when working on BusyBox or another non-GNU system.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

BashCommand Linefile managementLinuxls CommandUbuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.