Delete files 100 at a time and count total files

Answer #1 100 %

You can avoid xargs and do this in a simple while loop and use a counter:


while IFS= read -d '' file; do
    rm -rf "$file"
done < <(find "$destdir" -type f -print0)

echo "Deleted $count files from $destdir"

Note use of -print0 to take care of file names with whitespaces/newlines/glob etc.

Tags: linuxbash

You’ll also like:

© 2022 CodeForDev.com -