5 points · by antognini · 10y ago · 19 comments
autoload zmv
zmv '(*).baz' '$1.bar' mv *.bar *.baz
This is one place where Windows CMD works: ren *.bar *.baz
It can't work on Unix shells because wildcard expansion is done before the program (mv) is invoked.You can dry-run first with `-n` flag if you're worried you didn't do it right, which is admittedly too possible. A bit more verbose, but a bit more powerful too.
^ http://manpages.ubuntu.com/manpages/trusty/man1/prename.1.ht...
http://manpages.ubuntu.com/manpages/trusty/man1/rename.ul.1....
ls *.bar | while read f; do mv $f ${f%.bar}.baz; doneBefore you know it, you have a script you've debugged and tested.
Very useful stuff. E.g. mv nginx.conf{,.old}
for f in *.bar; do mv $f ${f%txt}baz; done mv $vflag $iflag $1 ${1%\.*}.$extI figured I would write something in the Unix philosophy to spare me (and maybe others) the trouble. It does exactly one thing, and it (hopefully) does it well. It was also fun to learn how to write a man page and do unit tests for a shell script.