View Full Version : rsync script to rewrite suffix - BASH, awk, sed, perl?

March 20th, 2013, 08:19 PM
trying to write up a script to put the suffix back.
heres what I have but can't get it to do anything :(
would like it to be name.date.suffix

rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~"--bwlimit=1024/mymounts/test1/ /mymounts/test2/
while IFS=. read -r -u 9-d '' name suffix date tildedo mv "${name}.${suffix}.${date}.~""${name}.${date}.${suffix}"done9<<(find .-type f -name "*.~"-print0)
-zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~"--bwlimit=1024/mymounts/test2/ /mymounts/test1/
while IFS=. read -r -u 9-d '' name suffix date tildedo mv "${name}.${suffix}.${date}.~""${name}.${date}.${suffix}"done9<<(find .-type f -name "*.~"-print0)still not rewriting as I would like, got file renamed as "test1.txt.20130320 95325.~"
Thanks in advance,

March 20th, 2013, 08:40 PM
Hi alienprdkt.

There are several syntax errors on your commands (lines split, commands joined together).

My guess is it was a copy/paste problem.

Could you edit your post so we can take a look at your actual scripts?

Kind Regards.

March 21st, 2013, 05:37 PM
Besides the copy-paste problem, there's another: your code presumes that files have only one suffix. How would you handle file.tar.gz? Also note that since the find is executed on the current directory (.), it will prepend ./ to each file name and the first variable you're reading into ($name) will be assigned empty value.


find -type -f -name '.*.*.~' -exec rename -vn 's:(\.[^./]+)(\.[^./]+)\.~$:$2$1:' {} +
n is there for testing purposes. When you're sure the command does what you want, remove n and rerun the command to do the actual renaming.

BTW, why would you use space-padded hours (%k) in the date format expression?