2

Is there a way to return a list of all folders on a given disk containing more than X images ?

The search should be recursive but X should not.

Example for X=100 :

Folder A
|_ folder A1 (containing 100 pictures)
|_ folder A2 (containing 50 pictures)
|_ 50 pictures

Should return "Folder A1" only.

1

for each image, print the name of the directory it lies in:

find \( -name \*.png -or -name \*.gif -or -name \*.jpg \) -printf '%h\n' |

uniq needs sorted input, but find prints files rather randomly. (In my test, even find -depth didn't help, don't ask me why.)

sort |

for every directory name, tell us how often it occurs:

uniq -c |

and finally, filter the lines we want:

while read count dir; do
    if [ "$count" -ge 100 ]; then echo "$count $dir"; fi
done
3

I am assuming all the pictures end with .png and X=100

find ./ -type d -exec sh -c 'count=$(ls "${0}"/*.png | wc -l); if [ "${count}" -ge 100 ];then echo "${0}"; fi ' {} \;

EDIT

It can be extended for files for any number of extensions and any value of X like below

export files='png jpg gif'
export X='100'
find ./ -type d -exec \
sh -c 'count=$(for i in ${files}; do ls "${0}"/*.${i};done | wc -l); \
if [ "${count}" -ge "${X}" ];then echo "${0}"; fi ' {} \;

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.