Recursive glob and batch rename in zsh
zsh: list only regular files recursively, then safely rename many files with zmv
setopt extendedglob; print -l **/*(.); autoload zmv; zmv '(*).txt' '$1.bak'
- tool
- bash12 commands
- tags
- zshtroubleshooting
More bash commands
-
set -euo pipefail; IFS=$'\n\t'Stop on errors, unset variables and failed pipes. Split words only on newline and tab
-
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT INT TERMRemove the mktemp dir on exit or signal. Note: quote $tmp so paths with spaces work
-
diff <(kubectl get cm a -o yaml) <(kubectl get cm b -o yaml)Process substitution compares two outputs without temp files
-
mapfile -t lines < file.txt; printf '%s\n' "${lines[@]}"mapfile -t strips newlines and keeps spaces, unlike word splitting in a for loop
-
f=/var/log/app.log.gz; echo "${f##*/}" "${f%.*}" "${f//log/LOG}"Get the basename, strip the extension and replace text without calling sed or basename