Listing Files in Linux: ls and Its Options
In this article
You list files in Linux with the ls command: type ls and press Enter to print the names of the files and directories in your current working directory. It is the first command most people learn because it answers the basic question of what is actually here before you copy, move, edit or delete anything. Everything else on this page is a variation on that one command.
What Plain ls Shows
Run with no arguments, ls prints the visible entries in the current directory in columns, sorted alphabetically. Names beginning with a dot, such as .bashrc or .config, are hidden and do not appear. The output does not distinguish files from directories, show sizes, or reveal permissions; it is a bare list of names.
If the output is empty, the directory contains no visible entries, which is normal for a freshly created folder. If you see a single name and then your prompt returns, that is also normal: ls prints one entry per line when the output is not going to a terminal, and in columns when it is.
You can pass one or more paths instead of relying on the current directory: ls /etc lists that directory, and ls file.txt simply echoes the name back if the file exists. Passing a file name is a quick existence check, though test -e file.txt is the cleaner way to script it.
Showing Hidden Files
The most common follow-up is "where did my config file go?" Files and directories whose names start with a dot are hidden by convention, not by any filesystem rule, and ls skips them unless you ask.
Use ls -a to show everything, including the special entries . (the current directory) and .. (the parent directory). Use ls -A to show hidden entries but omit those two, which is usually what you want because . and .. add noise without information.
A practical rule: when a program's documentation tells you to edit a file in your home directory and you cannot see it, add -A before assuming the file is missing.
Long Format and Sizes
ls -l switches to the long format, one entry per line, with seven columns: permissions, hard link count, owner, group, size in bytes, modification time, and name. This is the format to reach for when you need to know who owns a file or when it last changed.
By default the size column is in bytes, which is hard to read for anything large. Add -h for human-readable sizes: ls -lh prints values like 4.0K, 1.2M or 850M. The unit is a binary multiple, so 1K here means 1024 bytes, not 1000. That is a display convention, not an error.
The time column shows the modification time by default. ls -lu shows access time instead, and ls -lc shows the inode change time, which updates when metadata such as permissions changes. For most day-to-day work the default modification time is the one you want.
To sort by that time rather than by name, use ls -lt, newest first. Add -r to reverse any sort, so ls -ltr gives oldest first, which is handy when scanning a log directory for the file that has been sitting there longest.
Recursing and Filtering
ls lists one directory level. To walk into subdirectories, use -R: ls -R prints each directory followed by its contents, then each subdirectory and its contents, and so on. On a large tree this produces a lot of output, so pipe it to a pager such as less so you can scroll.
Shell globs do the filtering before ls ever runs. ls *.txt lists text files in the current directory; ls report-?.pdf matches a single character in that position. Because the shell expands the pattern, the result is a list of matching names, and if nothing matches, the unexpanded pattern is passed through and you get an error saying no such file.
To list a directory's contents without descending into it, ls -d */ prints only the subdirectory names, each with a trailing slash. That is the fastest way to see which folders exist when a directory holds many files.
For a compact, comma-separated list, ls -m is useful. For one name per line, which is what scripts usually want, ls -1 (the digit one) does it.
Reading the Long Output
Take a line like -rw-r--r-- 1 alice staff 2048 Jan 12 09:30 notes.txt. The first character is the file type: - for a regular file, d for a directory, l for a symbolic link. The next nine characters are permissions in three groups of three: owner, group, others, each with read, write and execute slots. The number after that is the hard link count, then owner, group, size, modification time and name.
A common misconception is that the size column for a directory tells you how much data it holds. It does not; it reports the size of the directory entry itself, typically a few kilobytes. To measure the contents, use du -sh on the directory instead.
Another misconception: a file that appears in ls is not necessarily readable by you. The permission string tells you what your account can do. If you get permission denied when opening a file you can see, check the third group of the permission string against your account's groups.
Colour, Aliases and Alternatives
Many distributions alias ls to ls --color=auto, which colours names by file type when output goes to a terminal and strips colour when piped. If colours appear on your system and you want plain text, run \ls to bypass the alias, or ls --color=never. Labels and defaults differ between distributions and shell configurations, so check with alias ls if the output surprises you.
Two related commands are worth knowing. tree draws a directory hierarchy as an indented diagram and is not installed by default everywhere. find searches recursively by name, size, age or permission and is the right tool when you need to match criteria rather than just list a folder.
A practical rule of thumb: use ls to look, ls -lh to inspect, and find to search. If your listing is longer than a screen, pipe it to less; if you need to act on the names, redirect to a file or use find -print0 with xargs -0 so names containing spaces survive intact.