If you’re a Linux user troubleshooting memory issues with your server, knowing which files are taking up the most space can be invaluable information. Luckily, you can have Linux find large files and organize them by size by combining a few simple commands.
The du command determines the size of files within a folder. By combining it with the sort and head commands, you can have Linux organize and report on the files in order of size. You can even designate how many responses you’d like to see.
Let’s say you’d like to see the 50 biggest files or directories in your /usr/local folder. To do so, just issue the following command:
du -a /usr/local | sort -n -r | head -n 50
If you’d like to change the number of listed responses, you can increase or decrease the number at the end of the command to alter the quantity of results.
Using this command, you can now have Linux find large files in any folder on your server.