KP Solutions

Solutions for Day to Day Technical Problems

Find Sizes of SubDirectories In One Command


Today, I was running out of disk space on my laptop; not quite unusual to happen. However, with this situation of out of disk, I had to get rid of the directories or files which are using most space and I no longer need.

Now, I can easily find the size of folder by issuing ‘du -skh <folder_name>’. But this gets tedious if you have 50 folders in one directory. I didn’t want to run same command fifty times. So, I had two options :

  1. Write a script
  2. Or find a command to take care of this situation
A one line command is way better than script any time for me. So, I cooked up an easy to use command:
find * -maxdepth 1 -exec du -skh {} \;

This one line command gave me the size and filename/foldername besides it. Exactly what I wanted. Hope this helps you!