Sunday 10 May 2020

How to count and delete the subfolder less than a number?

To list folder less than 10:-
find . -maxdepth 1 -type d -exec bash -c "echo -ne '{} '; ls '{}' | wc -l" \; |   awk '$NF<10'

To delete the folder less than 5:-
find . -maxdepth 1 -type d -exec bash -c "echo -ne '{} '; ls '{}' | wc -l" \; |   awk '$NF<5' | xargs rm -rf

No comments:

Post a Comment