10 Useful ‘ls’ Command Tricks for Linux Users

Most Linux users type ls -la dozens of times a day without exploring what the command can do. But beyond listing files, ls offers several useful options for sorting files by version, displaying file creation time, identifying file types, and producing output that is safer to use in scripts.

ls -l –time-style=full-iso notes.txt

source ~/.bashrc

If you regularly use long-iso, you don’t need to specify it every time. GNU ls reads the TIME_STYLE environment variable, so you can add the following line to your ~/.bashrc file to make it the default for your shell:
GNU coreutils 9.0 introduced the --zero option, which separates filenames using a null character () instead of a newline. Since Linux filenames cannot contain null characters, this provides a reliable way to represent filenames without ambiguity.
The -v option, also available as --sort=version, solves this by recognizing numeric sequences within filenames and sorting them in natural version order:

ls -w 0

ls –zero *.txt | xargs -0 wc -c

source ~/.bashrc

For example, to list files and directories by size, with the largest entries first, use -S:

How ls Decides What to Show

By default, ls sorts entries alphabetically by name. When using a long listing (-l), it displays the modification time (mtime). When writing directly to a terminal, it arranges filenames in columns.
If you prefer this layout every time you use ls, you can create a shell alias in your ~/.bashrc file. You can also combine it with the TIME_STYLE setting from the first example:

ls -l –time-style=long-iso

ls -l –time=birth –time-style=long-iso notes.txt

GNU ls can display a file’s birth time, also known as its creation time, using the --time=birth option:
The -w option, also available as --width, lets you specify the output width in characters. For example, setting the width to 80 characters gives ls a fixed width to work with:
After learning how to display timestamps consistently, the next step is understanding which timestamp you’re looking at. Linux tracks several timestamps for each file, but ls -l displays the modification time (mtime) by default, which changes whenever the file’s contents are modified.
The most useful sorting options include:
It’s important not to confuse -F with -p. The -p option adds a trailing / only to directory names, while -F adds the appropriate indicators for several file types.
These formats are useful when you want to change how filenames are presented without changing which entries are listed.
The long-iso style is particularly useful for system administrators because it displays the date and time in a predictable YYYY-MM-DD HH:MM format:
By default, ls -l displays usernames and group names by resolving the numeric user ID (UID) and group ID (GID) associated with each file. The -n option displays these numeric IDs instead, making it easier to identify the actual ownership values:

ls -1 -v app-*

ls (GNU coreutils) 9.4
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.

ls –zero -t — *.txt

total 2.1M
-rw-r–r– 1 tecmint tecmint 2.0M Oct 27 10:25 backup.sql
drwxr-xr-x 2 tecmint tecmint 4.0K Oct 27 10:25 docs
drwxr-xr-x 2 tecmint tecmint 4.0K Oct 27 10:25 scripts
-rwxr-xr-x 1 tecmint tecmint 10 Oct 27 10:25 deploy.sh

GNU ls provides the --sort option for choosing how directory entries are ordered. Many sort options also have shorter command-line equivalents.
This means app-1.10.tar.gz appears before app-1.9.tar.gz because the character 1 comes before 9, even though version 1.10 is newer.
One important exception is Ubuntu 26.04, which uses the Rust-based uutils coreutils implementation by default rather than GNU coreutils.
File ownership is particularly important when transferring files between Linux servers, working with shared storage, or troubleshooting container permissions.

app-1.10.tar.gz app-1.9.tar.gz archive.tar.gz backup.sql data.csv deploy.sh* docs/ latest-notes@ notes.txt report.pdf scripts/

And if any of these options behaves differently on your distribution, feel free to post your ls --version output and the error in the comments so we can look at it together.

ls -1 -v app-* | tail -n 1

When you list very large directories, such as a mail spool or a cache with hundreds of thousands of files, plain ls can take a long time because it reads and sorts every entry before printing anything. Using ls -U skips the sort and starts printing straight away, and adding -f also turns off colours and the extra stat calls they need.
If you’d like to build the same depth of knowledge across the rest of your everyday toolkit, our 100+ Essential Linux Commands course on Pro Tecmint walks through the commands sysadmins use every day, with practical examples for each one.

If this helped you finally see when a file was created instead of when it was last edited, share it with someone who’s still digging through backups to answer that question.

3. Sort Release Files Correctly with -v (Version Sort)

find . -maxdepth 1 -type f -name ‘*.txt’ -print0 | xargs -0 wc -c

The --group-directories-first option solves this by displaying directories before regular files, while preserving the selected sort order within each group.
You can also combine version sorting with tail command to retrieve the highest version number, which is useful in shell scripts:
The previous options focus mainly on making directory listings easier to read. However, when using filenames in shell scripts or passing them between commands, ordinary ls output can create problems.

total 2064
-rw-r–r– 1 tecmint tecmint 0 2026-10-27 10:25 app-1.10.tar.gz
-rw-r–r– 1 tecmint tecmint 0 2026-10-27 10:25 app-1.9.tar.gz
-rw-r–r– 1 tecmint tecmint 2097152 2026-10-27 10:25 backup.sql
-rwxr-xr-x 1 tecmint tecmint 10 2026-10-27 10:25 deploy.sh
drwxr-xr-x 2 tecmint tecmint 4096 2026-10-27 10:25 docs

Now that you’ve seen each option on its own, the most practical way to use them is to combine the ones you like into a few aliases, so you get the benefit without remembering every flag. A short set of lines in ~/.bashrc covers most daily needs:
For example, UID 1000 might belong to one user on your source server and a completely different user on the destination server. While ls -l displays the username resolved on the current system, ls -ln shows the numeric UID and GID without relying on those name lookups.
This is particularly useful when transferring files between servers using rsync or tar, working with NFS shares, or troubleshooting permissions inside containers.

4. Sort Files by Size, Time, or Extension with –sort

For example:
For general-purpose scripting, however, find with -print0 is usually a better choice because it is designed for reliably traversing directory trees and handling filenames safely:

We’d love to hear which ls options you’ve added to your own ~/.bashrc. Do you use –group-directories-first in your aliases, or do you prefer a different tool such as eza for directory listings?

-rw-r–r– 1 tecmint tecmint 6 2026-10-27 10:25:45.772729598 +0530 notes.txt

Most of these options turn a long pipeline into a single ls command, and the aliases above make the most useful ones part of your daily routine.

app-1.9.tar.gz
app-1.10.tar.gz

Recent GNU coreutils versions also support --classify=auto, which automatically enables classification only when output is directed to a terminal. This is useful when you want file-type indicators for interactive use without adding characters to redirected output.
Once you’ve learned to work with timestamps, another common problem is sorting files with version numbers in their names. By default, ls sorts filenames alphabetically, comparing characters from left to right.

5. List Directories Before Files with –group-directories-first

However, when its output is redirected to a file or piped to another command, it automatically switches to one entry per line. This is why ls | wc -l can count entries correctly even when the same directory appears in multiple columns on your screen.
You might also like:

app-1.10.tar.gz app-1.9.tar.gz archive.tar.gz backup.sql data.csv deploy.sh docs latest-notes notes.txt report.pdf scripts

ls -lhS

ls –classify=auto

Version sorting is useful for release files, but system administrators often need to answer other questions, such as which files are taking up the most space or which ones were modified most recently.

ls -ln notes.txt

app-1.10.tar.gz

ls -l –time-style=+’%d %b %Y %H:%M’ notes.txt

One more thing to remember: copying a file with cp or extracting it from an archive creates a new filesystem object. Its birth time generally reflects when the new copy was created, not when the original file was first created.
By default, ls -l displays timestamps differently depending on a file’s age. Recent files show the time, while older files show the year. This inconsistent format makes it harder to compare timestamps at a glance, especially when managing files across multiple releases.

ls -F –group-directories-first

Although many familiar options behave similarly, some newer features may be unavailable or behave differently. We’ll highlight compatibility considerations where necessary.
Finally, if you share scripts with colleagues who run Ubuntu 26.04, test them against the uutils version of ls before relying on newer options like --zero or --hyperlink, since GNU-specific behaviour is the most likely place for differences to appear.

9. Display Numeric UID and GID with -n

export TIME_STYLE=long-iso
alias ll=’ls -lh –group-directories-first’

Before trying the examples, check whether your system uses GNU coreutils:
You now know how to make ls show readable timestamps and real creation times, sort files by version, size, and extension, list directories first, mark file types correctly with -F, and produce output that is safe to pass into scripts.
The –-time-style option solves this problem by letting you choose a consistent timestamp format for every entry.
Sometimes, however, you need to know when a file was originally created on the filesystem. For example, you might want to determine when an unfamiliar configuration file first appeared on a server.
The -m option, equivalent to --format=commas, displays filenames separated by commas and arranges them across as few lines as possible:
This makes -n a useful option when investigating ownership mismatches across systems.

10. Produce Null-Terminated Filenames with –zero

By default, ls determines the available output width from the terminal and arranges filenames accordingly. This usually works well, but the layout can change when working in narrow terminal windows, tmux panes, or remote SSH sessions.
In this guide, we’ll explore 10 useful ls options that can make everyday Linux administration easier. The examples were tested with GNU coreutils 9.4 and are applicable to common Linux distributions, including Rocky Linux, AlmaLinux, RHEL, Debian, and Ubuntu.
Sometimes you don’t need a traditional column or long listing. For example, you might want to copy a list of filenames into a support ticket, email, or chat message.
Keep in mind that birth-time availability depends on the filesystem, kernel, and system interfaces used to retrieve the timestamp. If a birth time is unavailable, GNU ls displays a placeholder rather than a valid creation date.

export TIME_STYLE=long-iso

You can reverse any of these sorting orders with -r. For example, combining -t with -r lists the oldest modified files first and the newest at the bottom:

-rw-r–r– 1 1000 1000 6 Oct 27 10:25 notes.txt

-rw-r–r– 1 tecmint tecmint 6 27 Oct 2026 10:25 notes.txt

app-1.10.tar.gz, app-1.9.tar.gz, archive.tar.gz, backup.sql, data.csv,
deploy.sh, docs, latest-notes, notes.txt, report.pdf, scripts

export TIME_STYLE=long-iso
alias ll=’ls -lh –group-directories-first’
alias lt=’ls -lht’
alias lv=’ls -1v’

docs/
scripts/
app-1.10.tar.gz
app-1.9.tar.gz
archive.tar.gz
backup.sql
data.csv
deploy.sh*
latest-notes@
notes.txt
report.pdf

This option appends a character to each entry to identify its type, making it easier to distinguish directories, executable files, and symbolic links without using colors or a long listing.
And if you’re preparing for a sysadmin job, the Linux Interview Handbook covers 240+ questions, including the ls and file-management questions interviewers like to ask.

Conclusion

For example:
That is usually enough until you need to find the newest release archive in a directory full of versioned files, check when a configuration file was created, or pass filenames to a script without breaking on spaces or special characters.

ls -F

-rw-r–r– 1 tecmint tecmint 6 2026-10-27 10:25 notes.txt

If you work with Linux servers, ls is probably one of the first commands you run after logging in. For most users, the command stops at ls -l or ls -la.
The good news is that GNU ls, included in GNU coreutils, already provides options for handling these tasks. In many cases, you don’t need to combine it with sort, awk, or stat to get the information you need.

Similar Posts