How to use the ls command to list files in a directory sorted in reverse order by file size?

Published on Aug. 22, 2023, 12:20 p.m.

You can use the ls command with the -S option followed by the -r option to achieve this. Here’s the command:

ls -Sr /path/to/directory

Breaking down the options:

  • -S: sorts by file size instead of by name
  • -r: reverses the sorting order

This will list all files in the specified directory sorted in reverse order by file size.

Note that this may take some time to execute, especially if the directory contains many large files.

Also, keep in mind that the -S option sorts files by size, not by size on disk. If you want to sort by size on disk, you can use the -h option to display file sizes in a human-readable format, but note that this option is not available on all systems.

Tags:

ls