Skip to main content

Find, Grep, and Bulk Operations

# Safe log cleanup
find /var/log -name '*.log' -print0 | xargs -0 rm -f

# Parallel hashing
find . -type f -print0 | xargs -0 -P 8 sha256sum

# Compress text files
find . -name '*.txt' -print0 | xargs -0 gzip

# Move logs with placeholder mode
find . -name '*.log' -print0 | xargs -0 -I{} mv {} /tmp/logs/
  • Prefer find -print0 | xargs -0 for filenames.
  • Use echo or -t first before destructive commands.