bash - Recursively pointing out the number of files in directories -


what command in finding out directories beneath of root containing more given number of files xyz (assuming xyz 1000) , saving output of returned number(s) , directory/ies in file (or better: variable)?

find . -type d | while read dir;     printf '%d\t%s\n' $(find "$dir" -maxdepth 1 -type f | wc -l) "$dir" done | sort -rn 

this prints each directory , how many files in it. sorts them ones files first.

if want limit printout directories @ least $limit files, do:

find . -type d | while read dir;     count=$(find "$dir" -maxdepth 1 -type f | wc -l)     (($count >= $limit)) && printf '%d\t%s\n' "$count" "$dir" done | sort -rn 

to make robust , handle unusual file names whitespace , other special characters in them, add few flags find , read. technically, file names allowed have tabs , newlines in them, it's idea write scripts defensively these types of file names don't cause problems.

find . -type d -print0 | while read -d $'\0' -r dir;     count=$(find "$dir" -maxdepth 1 -type f -exec echo \; | wc -l)     (($count >= $limit)) && printf '%d\t%s\n' "$count" "$dir" done | sort -rn 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -