How do I sort files by size using the ls command in Linux?

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

To sort files by size using the ls command in Linux, you can use the -S option. Here’s an example:

ls -lS

This will list all files in the current directory, sorted by size with the largest file shown at the top. You can also use other options with the ls command, such as -h to display the file sizes in human-readable format, or -r to reverse the order of the listing. For example:

ls -lhSr

This command will show all files in the current directory, sorted by size with the smallest file shown at the top, and the file sizes displayed in a human-readable format.

Tags:

ls