ls command

Sorting ‘ls’ command output by filesize

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.

Linux ls command - How to show the permissions and size of a directory

How to see the permissions and size of a directory

Here's a short story :) on how to look at files and directories on a Unix/Linux computer system. I've seen so many people do this the hard way that I thought I should finally write something about it.