How to sort files by size in Linux Ubuntu. Learn how to list directories by size in Linux or list files by size in gb in Linux Ubuntu Systems.
How To Find And Sort Files By Size In Linux
You can use one of the following commands to find and sort files by size in Linux Ubuntu:
$ ls -lhS
$ ls -l
$ ls -lS
$ ls -lhS
Note that the command option ‘-h’ or ‘–human-readable’ is used to get the result in human readable format. It is used to append a size letter to each size, such as ‘M’ for mebibytes. Powers of 1024 are used, not 1000; ‘M’ stands for 1,048,576 bytes. This option is equivalent to ‘–block-size=human-readable’. You can also use the ‘–si’ option if you prefer powers of 1000.
List files by their size in reverse order
If you want to display the result in ascending order and show bigger files at the bottom and smaller files at the top, you can use the command option -r with the ls -lhSr command.
$ ls -lhSr
If you want to get the list of 10 biggest files in a directory, you can use the following command:
$ ls -lhS | head -11