Quick Linux Tip #15:
Try: time find /tmp/cache -type f -name '*.tmp' -print0 | xargs -0 -n 100 -P 8 rm
Info: -print0 outputs null-separated filenames. -0 tells xargs to expect them. -n 100 batches 100 files per rm call. -P 8 runs 8 parallel processes.
Examples:
- $ find /var/log -name '*.gz' -mtime +30 -print0 | xargs -0 -P 4 rm
- $ find /data -name '*.raw' -print0 | xargs -0 -P 8 -I {} convert {} {}.jpg
- $ find /tmp -type d -empty -print0 | xargs -0 -P 4 rmdir
Note: Use nproc to see CPU count. -n batching avoids "argument list too long" errors. Massive speedup vs serial deletion.
Leave a Reply