rename works with the same expressions (eg s/from/to/). In my example i cut main part of the name ($1), original extension ($2) and the number between ~ ~ ($3) and construct the new name off these...
Type: Posts; User: Vaphell; Keyword(s):
rename works with the same expressions (eg s/from/to/). In my example i cut main part of the name ($1), original extension ($2) and the number between ~ ~ ($3) and construct the new name off these...
renaming will be fine
$ rename -nv 's/(.+)[.]([^.]+)[.]~(.+)~/$1--$3.$2/' *~*~
test.txt.~1~ renamed as test--1.txt
test.txt.~2~ renamed as test--2.txt
test.txt.~3~ renamed as test--3.txt...
add -v switch to make mv verbose and check what happens
you should get something like this:
`1/2/test.txt' -> `txt/test.txt'
`1/test.txt' -> `txt/test.txt' (backup: `txt/test.txt.~1~')...
in theory exactly that should happen.
yes, echoing first is a smart thing to do, never run mv/rm if you are not absolutely sure what will happen as there is no undo.
1. it's easy to automate find
ext=( "*mp3" "*avi" )
find_opt=()
for e in "${ext[@]}"
do
(( ${#find_opt[@]} )) && find_opt+=( "-o" )
find_opt+=( "-iname" "$e" )
done