Loading...

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:

destdir='/example-dir/'
count=0

while IFS= read -d '' file; do
    rm -rf "$file"
    ((count++))
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 -