October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk9 min

The ls Command in Linux and Unix: Options and Examples

A practical, portability-aware guide to the Linux and Unix ls command: list hidden files, read long output, recurse, sort by time or size, inspect symlinks and avoid scripting pitfalls.

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 lists information about files and directories. Run it without an operand to show the current directory, add -a to include dot files, -l for metadata, -R for recursive output, and sorting options such as -t or -S to change the order. The details of some flags differ between GNU/Linux and other Unix systems, so this guide marks extensions and shows portable choices.

What ls does

The GNU Coreutils manual defines ls as a program that “lists information about files (of any type, including directories).” Its general form is ls [OPTION]... [FILE].... With no file argument, it acts as though you supplied . and lists the current working directory. When you name a directory, ls normally displays that directory’s immediate contents rather than the directory entry itself; it does not descend into subdirectories unless you request recursion.

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.

Entries whose names begin with a period are excluded by default. This is a name-selection rule, not a statement about whether the files are special or safe: configuration files, version-control metadata and other ordinary files can all be hidden this way. The command reads directory entries and, for long formats, asks the filesystem for metadata such as permissions, ownership, size and timestamps.

Basic listing patterns

Goal Command What to expect
List the current directory ls Immediate, non-hidden entries in the current working directory.
List a named directory ls /var/log Contents of /var/log, not the directory entry for /var/log itself.
Inspect one or more files ls report.txt image.png Information about the named operands; shell expansion may add more names before ls runs.
List several directories ls src tests A separate section for each directory, with headings when needed.
List a directory entry itself ls -d /var/log The directory is treated as an item; its contents are not opened.

Options and operands can be intermixed by GNU ls, but scripts are clearer and more portable when options come first, for example ls -l -- "$path". The -- marks the end of options so a filename beginning with a hyphen is not interpreted as a flag.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Hidden files: -a versus -A

Show every entry with -a

ls -a includes names beginning with .. In directories, that includes the special entries . (the directory itself) and .. (its parent), in addition to files such as .profile or .config.

Show almost all entries with -A

ls -A includes hidden names but omits the implied . and .. entries. It is usually the more convenient choice for surveying a directory without the two navigation entries. POSIX defines both -a and -A; use the uppercase form where you want “all real names” rather than every directory marker.

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

Hide selected names (GNU extension)

GNU ls also supports pattern-based hiding, including the long option --hide=PATTERN. This is implementation-dependent and should not be placed in a script intended for arbitrary Unix systems. Remember that shell globbing happens before ls receives arguments, while --hide controls names that ls would otherwise display.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Long listings and metadata

Reading ls -l

ls -l requests a long format. A typical line contains a file-type and permission field, link count, owner, group, byte size, a modification timestamp and the name. The exact columns and timestamp presentation are implementation-dependent, and a directory’s reported size is the size of its directory record, not the sum of all files beneath it.

For a symbolic link, the usual long output shows the link name followed by -> and its target. To inspect the link itself rather than follow it, use the default behavior; to dereference links when collecting information, GNU ls -lL linkname follows the link and reports the target’s metadata. The -L behavior is available in POSIX implementations, but details of displayed fields can vary.

Comparing -l and -la

Command Metadata Name selection Typical use
ls -l Long format Omits dot files Inspect permissions, ownership, sizes and times for ordinary entries.
ls -la Long format Includes dot files, plus . and .. Audit a directory’s complete visible entry set.
ls -lA Long format Includes dot files, omits . and .. Complete hidden-file view without navigation entries.

Combined short options such as -la are equivalent to supplying -l and -a separately on standard implementations. Keep in mind that -h is not part of the POSIX baseline: GNU and many Unix versions use ls -lh to print sizes with units such as KiB or MiB, but scripts should not assume it exists everywhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Additional metadata controls

  • GNU --author adds an author column where the underlying filesystem and implementation provide one.
  • GNU --block-size=SIZE changes the unit used for reported block counts and related size displays. It is separate from the human-readable presentation selected by -h.
  • Inode and block-oriented flags are available in GNU and POSIX variants, but their exact output and accounting depend on the filesystem. Treat these fields as diagnostic data, not as portable machine-readable records.

Sorting entries

Names are the normal sort key. The comparison is locale-sensitive, so the order can differ between systems or user sessions. Sorting flags can be combined with long format and with reverse order, but combinations and defaults are not identical across every Unix implementation.

Purpose Example Qualification
Newest modification time first ls -lt -t sorts by modification time; tie handling and timestamp display vary.
Largest size first ls -lS -S is supported by GNU and many Unix systems, but check the target’s ls for strict portability.
Reverse the selected order ls -ltr -r reverses the result, producing oldest-first when combined with -t.
Use access time ls -lu POSIX provides time-selection flags, but atime updates may be disabled or delayed by mount options.
Use status-change time ls -lc This is metadata change time, not file creation time; availability and meaning follow the Unix implementation.

For a stable order in automation, set the locale explicitly: LC_ALL=C ls -1 -- "$dir". GNU documentation recommends LC_ALL=C when predictable ordering across locales matters. The -1 option requests one entry per line where supported. Do not parse decorative, column-formatted output as if it were a data format; filenames can contain spaces, tabs, newlines and other characters.

Recursive listings

Use -R for a tree-like inventory

ls -R project lists project and then recursively lists each directory below it. GNU and POSIX define -R. On a large source tree, the output can be enormous and difficult to search; recursion also follows the directory structure in ways that may expose mounted filesystems or unexpectedly large areas.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Limit the scope deliberately

  • Start with a specific subdirectory rather than / or your entire home directory.
  • Use ls -ld */ when you only need immediate subdirectory entries and do not want recursion.
  • Combine -A only when hidden directories are relevant; otherwise the default omission keeps the result manageable.
  • For programmatic traversal, use a purpose-built file-walking tool or language API instead of parsing recursive display output.

Directories, symlinks and operand behavior

Three flags answer common questions about what ls opens:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • -d: list a directory operand as an item and do not list its contents. This is useful for checking permissions on the directory itself: ls -ld /srv/app.
  • -L: dereference symbolic links when gathering information. With ls -lL linkname, the metadata is for the target; a broken link can therefore produce an error.
  • -R: descend into directory contents recursively. It changes traversal scope, not merely formatting.

Without -L, a symlink is generally reported as a link, while a directory operand is opened and its contents are listed unless -d is present. These distinctions matter when checking deployment paths, permissions or links that may point outside the directory you are examining.

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

Output formatting on terminals and in scripts

GNU ls adapts its layout to the destination. On an interactive terminal it commonly uses columns; when output is redirected, it prints one entry per line. Quoting and escaping rules protect unusual characters in display, and color or file-type classification may be enabled by the implementation or by aliases in your shell.

Aliases can silently add flags such as color or human-readable sizes. To see the unaliased command in an interactive shell, use command ls or ls. For a script, invoke the command with explicit options and a controlled locale, and avoid depending on color, column spacing or human-readable units.

A safer inspection pattern

  1. Choose the directory and quote it: dir=/var/log.
  2. Set a deterministic locale for this invocation: LC_ALL=C.
  3. Request one name per line: LC_ALL=C ls -1 -- "$dir".
  4. If you need metadata for a known path, pass that path directly with -ld rather than scraping a directory listing.

Even one-per-line output is not a robust serialization format because a filename itself may contain a newline. If another program must consume names safely, use an interface that supplies delimiters or structured records designed for that purpose.

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

Linux versus Unix portability

POSIX supplies a useful baseline synopsis: ls [-ikqrs] [-glno] [-A|-a] [-C|-m|-x|-1] [-F|-p] [-H|-L] [-R|-d] [-S|-f|-t] [-c|-u] [file...]. This covers the principal controls for name inclusion, long or classified output, traversal, links and time or size sorting. Individual systems can still differ in columns, tie-breaking, color defaults and accepted combinations.

Option or behavior Portability status Advice
-a, -A POSIX Portable way to include all or almost all dot files.
-l, -d, -R, -L POSIX Use for long metadata, directory operands, recursion and link dereferencing.
-1, -C, -m, -x POSIX Select one-per-line, column, comma-separated or horizontal layouts as supported.
-S GNU and many Unix systems; verify Do not assume strict POSIX availability without checking the target.
-h Common GNU extension Label Linux examples as GNU/common extensions when portability matters.
--color, --time-style, --block-size, --almost-all, --hide GNU long options Do not use in scripts that must run on non-GNU ls.

When a command must run on both Linux and another Unix, prefer the POSIX short options, test on each target implementation and avoid assumptions about output columns. GNU Coreutils documentation current to version 9.11 (2026) describes additional long options and GNU-specific behavior; those features are not automatically part of every Unix ls.

Exit status and diagnosing failures

GNU ls returns status 0 for success, 1 for minor problems and 2 for serious trouble such as an invalid option or failure to access a specified operand. A command can therefore print useful entries and still return nonzero if one of several operands could not be read.

  • “invalid option”: check whether the flag is GNU-only, correct the spelling, or replace it with a POSIX option.
  • “cannot open directory” or “permission denied”: verify the path with pwd, inspect each parent directory’s execute permission, and use an account authorized to traverse the location.
  • Missing hidden files: add -a or -A; do not mistake a clean default listing for an empty directory.
  • Unexpected order: check aliases, sort flags and locale; use LC_ALL=C for a reproducible byte-oriented order.
  • Wrong symlink details: decide whether you need the link’s own metadata or the target’s, then choose default behavior or -L accordingly.
  • Overwhelming output: remove -R, narrow the operand, or list only immediate directories with a glob such as */.

Practical command recipes

Task Command Reasoning
See permissions and owners, excluding dot files ls -l Long format without hidden names.
Audit every entry in the current directory ls -la Long format plus ., .. and dot files.
Audit hidden names without navigation entries ls -lA Long format plus almost all names.
Find recently modified entries visually ls -lt Modification-time sort, newest first.
Inspect largest entries first ls -lS Size sort where the implementation supports -S.
Check a directory’s own permissions ls -ld /srv/app -d prevents listing its contents.
Inspect a symlink target (GNU/common) ls -lL current -L dereferences the link.
Inventory a project recursively ls -R project -R descends through subdirectories; use on bounded trees.
Stable one-name-per-line output LC_ALL=C ls -1 -- "$dir" Controls locale and layout for human inspection or limited scripting.

What ls is—and is not

ls is an interactive inspection command and a compact way to request selected filesystem metadata. It is not a complete disk-usage calculator: a long listing’s size column reports each entry’s apparent byte size, while directory contents, sparse files, hard links and allocated blocks require different accounting tools. It is also not a safe general-purpose filename serialization format. Use it to look, verify and troubleshoot; choose APIs or specialized utilities when another program must process every pathname without ambiguity.

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

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.

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

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.