Project Wild Penguin 22.4.2017: To delete directories inside current directory whose contents are less than a given size


With GNU find and GNU coreutils, and assuming your directories don't have newlines in their names:

find . -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50' | cut -f 2-

This will list directories with total contents smaller than 50K. If you're happy with the results and you want to delete them, add | xargs -d \\n rm -rf to the end of the command line.

Command:

find . -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50' | cut -f 2- | xargs -d \\n rm -rf

Source: https://unix.stackexchange.com/questions/214089/command-to-delete-directories-whose-contents-are-less-than-a-given-size

Comments

Popular posts from this blog

ANPR Project Day 1: Standard Format of Indian Number Plate

ANPR Day 5: User requirement Analysis