what is the ls option to sort by file size?

2 days ago 2
Nature

The option to sort files by size using the ls command is -S (uppercase S). This sorts files by their size, with the largest files listed first. It is often combined with -l for long listing format and -h for human-readable file sizes, like this: ls -lhS. Additionally, you can use the alternative form --sort=size to achieve the same effect. Summary:

  • ls -S sorts files by size.
  • Combine with -l and -h for detailed, human-readable output: ls -lhS.
  • Optionally use --sort=size as an alternative.

This behavior is standard on Linux and Unix-like systems.