By Alvin Alexander. Last updated: November 30, 2021
I just noticed that some of the MySQL files on this website had grown very large, so I wanted to be able to list all of the files in the MySQL data directory and sort them by filesize, with the largest files shown at the end of the listing. This ls
command did the trick, resulting in the output shown in the image:
ls -Slhr
The -S
option is the key, telling the ls
command to sort the file listing by size. The -h
option tells ls
to make the output human readable, and -r
tells it to reverse the output, so in this case the largest files are shown at the end of the output.