Ls sorted by size, which can help us quickly filter out the files or directories that occupy the largest or smallest storage space size in the current directory.
The Linux ls -S option can be sorted by size from largest to smallest, or the ls -rS option can be sorted by size from smallest to largest.
- ls -S Sort files by size
- ls -r Reverse the order
ls sorted by size from largest to smallest
➜ ~ ls -S
ls sorted by size from smallest to largest
➜ ~ ls -Sr
However, you will find that although the above methods can be sorted by size, it is not easy for us to check. We usually use it with the ls -l option, which can display richer structured information.
- ls -l List in long format.
Usually, when we use the ls command to sort by size, we hope to make it easier for us to read. In addition to using the -l long format option, we still use the -h option.
- ls -hl It is used with the -l option to display the file size in bytes, kilobytes, megabytes, gigabytes…