If you use the terminal often, you probably know the ls command. It lists what’s in a folder, but if you add some flags it can do a lot more. You can view extra details, locate files faster, and get exactly the information you need. Here are some useful ls flags I use and why they help.
Related
How to Use the ls Command to List Files and Directories on Linux
The humble ls command can do a lot more than you think. Discover its hidden talents!
11
-l: Detailed Directory Snapshot
When you type ls without flags, you just get filenames. That’s often not enough. I usually want to know who owns a file, when it was last changed, and how big it is. To check all of these, run:
ls -l
Here, -l stands for long format. It gives a detailed, single-line report for each file, with permissions, owner, size, last modified date, and filename. This turns a simple list into a rich summary. However, the output can seem a bit complex at first, but it’s very useful, especially for troubleshooting.
10
-h: Get Human-Readable Sizes
There’s one issue with the previous ls -l command for a detailed directory snapshot: it displays file sizes in bytes by default, which can be hard to read for large files. To make them more readable, you can add the -h flag (for human-readable):
ls -lh
The -h flag converts those confusing byte counts into more understandable units, like Kilobytes (K), Megabytes (M), or Gigabytes (G). For example, a file that was shown as 1320 bytes will now appear as 1.3K, making it instantly clear.
9
-a: Shows Hidden Files
Sometimes, you might enter a directory where you expect certain files to be present, but ls doesn’t show them. This often happens with configuration files. On Linux and macOS systems, files that start with a dot (like .settings, .gitignore, or .bashrc) are hidden by default to keep your directory view uncluttered. However, these are often the exact files you need to edit.
Related
The Hidden Files in Your Linux Home Directory, Explained
If your home’s looking a little crowded, it may be time for a spring clean.
To display everything, use the -a (for all) flag with ls:
ls -a
or
ls -la
Without the -a flag, you wouldn’t see these important files.
8
-t: Sort by Most Recent Changes
When working with lots of files, especially logs, backups, or temporary files, it’s easy to lose track of what changed last. Fortunately, with the -t option of ls you can sort files by modification time by showing the most recently changed files at the top.
ls -t
In addition, I usually combine it with the -l flag to get more detailed information:
ls -lt
This gives a complete snapshot, file size, ownership, and last modified date—sorted with the newest files first.
7
-S: Sort by File Size (Largest First)
When my system slows down, or I get a low disk space warning, my first step is to check which files are using the most space. To locate those files, open your specified directory and run:
ls -lS
This command sorts files by size, from largest to smallest. Just like -t sorts by time, -S helps you find the heavy hitters in your directory. I usually add the -h flag to make file sizes easier to read:
ls -lhS
Now file sizes appear in KB, MB, or GB, making it easier to identify space hogs.
Related
I Dug Up the Biggest Files on My Linux PC, Here’s What I Found
Thanks to the ncdu command, I went on a fishing trip and reeled in some real whoppers.
6
-r: Reverses the Sort Order
The -r flag reverses the sort order. So if you’re using -t to show the newest files, adding -r will display the oldest ones first. You must combine -r with another sorting flag because it is ineffective when used alone.
To see the oldest files, run:
ls -ltr
Now files that haven’t been touched in the longest time appear at the top. You can use this to spot forgotten notes, stale logs, or outdated project files ready for archiving or deletion.
You can also use it to view the smallest files, just replace -t option with the -S:
ls -lSr
That puts small scripts, config files, or lightweight files at the top of your list.
5
-R: Recursively Lists Subdirectories
By default, ls only shows what’s in the current directory. But sometimes you need to see everything—folders, subfolders, and all the files inside them. For example, after extracting a zipped archive, you might want to verify what was extracted and ensure nothing important is hidden in subfolders.
Related
How to Recursively Search Directory Names in Linux
Everything in Linux is stored in directories, and when writing bash scripts, it’s often useful to search for directories by name.
To do that, run:
ls -R
The -R flag stands for recursive, and it tells ls to dig through every subdirectory and list all their contents too.
This is especially useful when you’re managing a large codebase or checking that all your files are saved across nested folders. It gives you a complete snapshot of everything without having to open each folder individually.
Be cautious though—running this in a massive directory can flood your screen. To manage the output, combine it with less or grep:
ls -R | less
ls -R | grep ‘report.pdf’
Now you can scroll through or search the output easily.
4
-d: Lists Directories, Not Their Contents
Sometimes, you want information about the directory itself, not what’s inside it. The -d flag does exactly that. It shows the folder’s name and properties without listing its contents.
Normally, when you run:
ls folder_name
You see what’s inside the folder. But if you run:
ls -ld folder_name
You’ll see the folder itself. This is a great way to check which folders exist, along with their permissions and metadata, without viewing everything inside.
3
-F: Adds Type Symbols
When you run the ls command, the output of the files and folders always looks the same. To find out what kind of file each item is, you can use the -F flag:
ls -F
Now you’ll see little symbols added at the end of file names. For example, the / means it’s a folder, * means it’s a program or script you can run and @ means it’s a shortcut (symlink). So instead of guessing, you can instantly tell if something is a folder you can go into, or a file you can run.
2
-1: One File Per Line
By default, ls shows your files in a bunch of columns. That’s fine for quick looks, but it can get messy, especially when you have a lot of files. Try this:
ls -1
Now you’ll see one file or folder per line, just a simple list going down. Nothing is squeezed together. You can use this when you want to copy a list of file names, or when you’re writing a script and need to work with files one at a time.
In addition, you can also easily count the files by piping the output to wc:
ls -1 | wc -l
That just tells you how many files are in the folder.
This format is also useful when you plan to pipe (|) the output of ls into another command for processing. Many text-processing tools (like grep, awk, sed, or xargs) expect one item per line. If ls outputs on multiple columns, piping can get messy. The -1 flag ensures clean, predictable input for the next command in your pipeline. For example, run this:
ls -1 | grep ‘.txt$’
This finds all .txt files.