File Operation Patterns
Bulk rename — append .bak extension to all .conf files
find /tmp/demo -maxdepth 1 -name '*.conf' -print0 | xargs -0 -I{} mv {} {}.bak
Bulk copy to staging directory
find /tmp/demo -name '*.log' -print0 | xargs -0 -I{} cp {} /tmp/staging/
Bulk chmod — set 644 on all regular files in a tree
find /tmp/demo -type f -print0 | xargs -0 chmod 644
Bulk chown — set ownership recursively
find /tmp/demo -type f -print0 | xargs -0 sudo chown evan:evan
Bulk sha256sum — checksum all files in a directory
find /tmp/demo -type f -print0 | xargs -0 sha256sum
Create directories from a file list
printf 'alpha\nbeta\ngamma\ndelta\n' | xargs -I{} mkdir -p /tmp/demo/{}
Bulk symlink creation — link configs into a target directory
find ~/dotfiles -maxdepth 1 -name '*.conf' -print0 | xargs -0 -I{} ln -sf {} /tmp/demo/
Move files by date into YYYY/MM directories
find /tmp/demo -maxdepth 1 -type f -print0 | xargs -0 -I{} sh -c '
d=$(stat -c %Y "$1" | xargs -I@ date -d @@ +%Y/%m)
mkdir -p "/tmp/sorted/$d"
mv "$1" "/tmp/sorted/$d/"
' _ {}
Strip extensions from filenames — rename .txt to no extension
find /tmp/demo -name '*.txt' -print0 | xargs -0 -I{} sh -c 'mv "$1" "${1%.txt}"' _ {}
Bulk convert line endings — dos2unix via xargs
find /tmp/demo -name '*.sh' -print0 | xargs -0 -I{} sed -i 's/\r$//' {}