I want to rename all files which contain the sub-string 'foo
', replacing it with 'bar
' within a given folder.How can I accomplish this?
Update:
for i in ./*foo*; do mv "$i" "${i//foo/bar}";done
works!!!
If you have the rename(1)
that came with perl
(Debian provides it), you can use:
cd /path/to/directory
rename 's/foo/bar/g' *
If you have the other rename(1)
(I've seen it in Red Hat Enterprise Linux and some other distributions, it comes from util-linux), you can try:
cd /path/to/directory
rename foo bar *foo*
You can check which version of rename
you have by trying rename -V
. If it doesn't recognize the flag, it's the perl version. If it prints version information, it's the other version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With