Site icon LinuxCommands.site

Sort files or folders by size with ls command in linux/unix

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 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 -Sl
ls -Slr

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 -Slh

ls -Slhr

Exit mobile version