LilaQ LilaQ - 11 months ago 52
Bash Question

Bash scripts that list folders with subfolder / folders with multiples files bigger than X

I'm looking for a bash script, than can list all the folders, that have

a) subfolders


b) more than 1 file bigger than size X

Sadly my bash-fu is not that good to accomplish something like this, I wouldn't even know what to pipe together for something like this.

Regarding a) I have no idea where to start (fiddle with

ls -R

Regarding b) I already can list all files bigger than size X with:

du -sm * | awk '$1 > 500'

But from there on, I'm stuck.

Thanks a lot for your help in advance guys.

Answer Source

For a) find with awk and sort

$ find . -type d | awk -F/ -v OFS=/ '{NF--} NF' | sort -u

find all directories, remove the last level, remaining ones are parents only with multiplicity, then filter. Assumes no newlines in filenames.

For b) similarly

$ find . -size +1M | awk -F/ -v OFS=/ '{NF--} NF' | sort -u 

this is for greater than 1Mb, if you want 500b, change to +500c