Skip main navigation
/user/kayd @ :~$ cat quirky-ls-command-tricks-linux.md

13 Quirky 'ls' Command Tricks Every Linux User Should Know: Hidden Command-Line Magic 13 Quirky 'ls' Command Tricks Every Linux User Should Know: Hidden Command-Line Magic

QR Code for Article
Karandeep Singh
Karandeep Singh
• 8 minutes

Summary

Uncover 13 genuinely quirky ls command options built right into Linux. These unconventional techniques will transform how you view directories and impress even veteran system administrators.

Beyond Basic Listing: The Quirky Side of ’ls'

The ls command is a daily companion for Linux users, but hidden within its man pages are genuinely quirky options that most people never discover. While everyone knows ls -l or ls -a, this guide explores the truly unusual ls command tricks built right into the command itself—no third-party tools required.

In this exploration of 13 quirky techniques, we’ll reveal the strange, wonderful, and occasionally bizarre options that the ls command’s developers buried in the codebase. These aren’t the options covered in beginner tutorials—they’re the peculiar flags and parameters that even experienced Linux users might raise an eyebrow at.

Let’s dive into these genuinely quirky ls command tricks that showcase the delightful eccentricity of Linux command design.

1. The Quote Everything Option (-Q)

One of the quirkiest ls command tricks involves the -Q option, which wraps every filename in double quotes:

ls -Q

This produces output like:

"document.txt"  "image.jpg"  "script.sh"  "strange file name.txt"

This odd option becomes genuinely useful when scripting with files that might contain spaces or special characters. Combined with other options:

ls -laQ

2. Classify Files with Strange Symbols (-F)

The -F option appends strange symbols to different types of files:

ls -F

Output appears with slashes, asterisks, and other indicators:

directory/  executable*  regular-file  socket=  symlink@

This quirky classification scheme uses:

  • / for directories
  • * for executables
  • @ for symbolic links
  • = for sockets
  • | for named pipes
  • > for doors (in some systems)

For even quirkier control, try:

ls --indicator-style=classify

Or the truly unusual:

ls --indicator-style=file-type

3. Sort by Extension, Not Name (-X)

Most users sort alphabetically, but the quirky -X option sorts files by extension instead:

ls -X

This creates unusual groupings where all .txt files appear together regardless of filename, followed by all .jpg files, and so on. For a truly strange sorting experience, combine with reverse ordering:

ls -rX

This sorts files by extension but in reverse alphabetical order of extensions. Files without extensions come last in normal mode but first in reverse mode.

4. Hide Specific Patterns (–hide)

The peculiar --hide option lets you selectively hide files matching a pattern:

ls --hide="*.txt"

What makes this quirky is that you can combine multiple patterns for very specific hiding:

ls --hide="*.txt" --hide="*[0-9]*" --hide="[a-m]*"

This creates a strange filtered view showing only files that don’t contain numbers, don’t start with letters a through m, and don’t end with .txt.

5. The Forgotten Access Time Listing (-u)

Most users know about modification time, but ls can also show the rarely used access time with the -u option:

ls -lu

This shows when files were last read rather than written, creating a quirky view into file usage. Even stranger, combine with time-style options:

ls -lu --time-style=full-iso

This reveals access times with microsecond precision, exposing a rarely seen dimension of your filesystem.

# Sample output with access times
-rw-r--r-- 1 user group 1234 2025-03-10 09:15:30.123456789 +0000 document.txt

6. Context-Aware Security Listings (-Z)

On systems with SELinux or similar security systems, the quirky -Z option reveals hidden security contexts:

ls -Z

This displays security labels most users never see:

unconfined_u:object_r:user_home_t:s0 file.txt

For a truly unusual view, combine security context with other formats:

ls -laZ

This security information is invisible with standard ls usage but reveals a whole dimension of Linux security most users never interact with.

7. Dereference Command Line Arguments Only (–dereference-command-line)

This unusually specific option follows symbolic links, but only for files specified on the command line:

ls --dereference-command-line symlink1 symlink2 directory_with_symlinks/

Even quirkier, try:

ls --dereference-command-line-symlink-to-dir

This only dereferences symlinks that point to directories specified on the command line but not those discovered during directory traversal. This hyper-specific behavior was clearly designed for a very particular use case.

8. Show Entry Per Line with Commas (-m)

The oddly formatted -m option separates entries with commas rather than newlines:

ls -m

This produces output like:

file1.txt, file2.txt, images, scripts, strange file.jpg

Combining this with other options creates even stranger output:

ls -mF

Which gives comma-separated entries with type indicators:

file1.txt, file2.txt, images/, scripts/, strange file.jpg

9. Almost No Output with -1 vs -l

The quirky difference between -1 (numeral one) and -l (letter l) confuses even experienced users:

ls -1

This produces a bare list with one entry per line but no details:

file1.txt
file2.txt
images

Compare with:

ls -l

Which gives the familiar detailed listing. The quirk is that -1 is the default behavior when output isn’t going to a terminal, creating confusion in scripts where the output seems to change unpredictably.

    graph TD
    A[ls command] --> B{Output to terminal?}
    B -->|Yes| C[Multi-column format]
    B -->|No| D[One entry per line]
    C --> E[Override with -1]
    D --> F[Already in -1 format]
  

10. Custom Block Sizes (–block-size)

The unusual --block-size option lets you view file sizes in arbitrary units:

ls -l --block-size=K

But you can get truly quirky with strange units:

ls -l --block-size=M
ls -l --block-size=G
ls -l --block-size=T

For even stranger behavior, try powers of 10 instead of powers of 2:

ls -l --block-size=MB

Or the truly esoteric:

ls -l --block-size="'1"

Which groups digits with single quotes as thousands separators.

0

11. Author Listing (–author)

The rarely-used --author option shows the file author, which is often identical to the owner but can differ in some filesystems:

ls -l --author

This exposes an additional column of information most Linux users never see:

-rw-r--r-- 1 user author group 1234 Mar 10 09:15 file.txt

This option reveals that Linux internally tracks both owners and authors, a distinction almost never utilized.

1

12. Bizarre Time Styles (–time-style)

The --time-style option offers some truly unusual date formatting options:

ls -l --time-style=locale
ls -l --time-style=iso
ls -l --time-style=full-iso

But the quirkiest option is creating your own format:

ls -l --time-style="+%Y-%m-%d %H:%M:%S.%N"

For maximum strangeness, try including non-time elements:

ls -l --time-style="+Week %V of %Y, day %j, %H:%M"

This displays timestamps like “Week 10 of 2025, day 069, 09:15” instead of conventional dates.

2

13. Version Sort (-v)

The peculiar -v option sorts files in “natural” version order, understanding that version 10 comes after version 2:

ls -v

This makes files like “file2.txt” appear before “file10.txt” - a behavior normal alphabetic sorting doesn’t provide.

For the full quirky experience, combine with other sort options:

ls -lSrv

This sorts files by size (largest last), but with version-aware naming. The result is a strangely specific yet occasionally extremely useful sorting method.

3
If you thought these were quirky, here are three even more obscure options: 1. `--show-control-chars`: Shows control characters as-is instead of using hat notation or octal escapes 2. `--zero`: End each output line with NUL rather than newline (for extremely specialized parsing) 3. `--hyperlink`: Output filenames as hyperlinks using a special terminal protocol

Practical Applications: When Quirky Becomes Useful

These ls command tricks might seem odd, but they solve real problems:

Dealing with Strange Filenames

The quote and escape options help when filenames contain spaces or special characters:

# Create a file with a problematic name
touch "file with spaces and $pecial characters"

# List it safely
ls -Q
ls --quoting-style=shell-escape

Creating Nicely Formatted Reports

The strange formatting options can create readable export files:

# Create a CSV-like listing
ls -la --time-style="+%Y-%m-%d" | tr -s ' ' ',' > file_report.csv

Debugging Security Issues

The -Z context option helps understand permissions problems on SELinux systems:

4
# Check why a file can't be accessed
ls -Z problematic_file.txt

Best Practices for Using Quirky ls Options

When utilizing these unusual ls command tricks:

5
  1. Document your usage - Quirky options aren’t obvious to others
  2. Consider script portability - Some options are GNU-specific
  3. Use aliases for complex combinations - Save typing and errors
  4. Check the version of ls - Options may vary between distributions
# Example of documenting a quirky ls trick
# Name: Version-sorted file listing with size
# Purpose: List files with natural version ordering
# Dependencies: GNU ls
# Creator: Karandeep Singh
ls -lSv

Conclusion: The Hidden Depths of Familiar Commands

These 13 quirky ls command tricks reveal that even the most fundamental Linux commands contain surprising depths and unusual features. The designers of these tools created options for remarkably specific scenarios, many of which remain unknown to the average user.

By exploring these quirky options, we gain not just practical tools but a deeper appreciation for the thoughtfulness and flexibility built into Linux utilities. The most basic commands often contain clever solutions to problems you haven’t encountered yet.

As you incorporate these quirky ls command tricks into your workflow, you’ll likely find that some solve problems you didn’t know you had, while others remain amusing curiosities. Either way, they offer a glimpse into the remarkable attention to detail that characterizes Linux tool design.

Question

Which quirky ls option surprised you the most or seems most useful for your workflow?

6

References and Further Reading

📥 Download ls Command Cheatsheet

Similar Articles

More from development

Knowledge Quiz

Test your general knowledge with this quick quiz!

The quiz consists of 5 multiple-choice questions.

Take as much time as you need.

Your score will be shown at the end.