List File Sizes in Terminal

Sometimes it's helpful to list out the files and folders in a directory and show the size of each file/folder in a readable format. You can easily accomplish this with the following command:

du -sh *

This will list out the contents of the current directory and the size of each file/folder. Take a look at the following screenshot:

Screen Shot 2020-07-17 at 11.04.42 AM.png

As you can see, in the example above we now know that the wallpapers folder is the largest folder in the current directory weighing in at 355 Megabytes.

Listing out the current directory file sizes may help when you need to clean up file that are taking too much space, or it may help if you need to see which directory contains the most content.

If you wish to show the file sizes in order of Largest first, you can pipe the command to sort -rn, like so:

du -sh * | sort -rn

This will now list the files in order by size.

Screen Shot 2020-07-17 at 11.10.51 AM.png

It may be helpful to add these commands as an alias, or you can just store them in main memory (your mind).

© 2020 DevDojo LLC. All rights reserved.