Reputation: 3297
I'm trying to rename multiple files in a directory. The intention is to remove the trailing _bkp extension. What I've come up with is as shown below, but as you all know, this wont work, but you get the idea. Any help??
find -iname "*.sql_bkp" -exec mv {} sed -e 's/\_bkp//g' {} \;
or
find -iname *.sql_bkp -exec mv {} $(sed -e 's/\_bkp//g' {}) \;
Upvotes: 1
Views: 72
Reputation: 3127
Try this -
$find -iname "*.sql_bkp" -exec basename {} _bkp \;
OR
$for i in *.sql_bkp; do mv "$i" "$(basename "$i" _bkp)";done
Upvotes: 0
Reputation: 784868
You can use:
find . -iname '*.sql_bkp' -exec bash -c 'echo mv "$1" "${1%_bkp}"' - {} \;
When you're satisfied with the output, just remove echo
before mv
Upvotes: 3