On my server I have a bunch of accounts that have WordPress installed and also have backup directories in the format: softaculous_backups.

I can find all the directories using the command:

$ find  / -type d -name "softaculous_backups" -ls

I can use commands to check the disk space used by each folder like:

$ du -smc * | sort -n
$ du -sh *


But, how do I combine the two commands into one, so I get output like:

Size                   Directory
123456789              /home/useraccount/softaculous_backups

How about that:

find / -type d -name "softaculous_backups" -exec du -sm {} \; | sort -n

For every found directory, du -sm is executed. After that all output is sorted numerically.

  • Note that you don't need to run one du instance per directory. You can use -exec du -sm {} + instead (though the output could be different if some of those directories share files (as hardlinks)). You may (or may not) also want to use -prune on those directories to avoid considering softaculous_backups directories inside other softaculous_backups directories (and save having to look for them inside). The sort -n part assumes file paths don't contain newline directories. May 19 '15 at 9:13
  • Holy cow that was BRILLIANT! Thanks so much, that works even better than expected! May 20 '15 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.