[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cp output format



On Thu, Jul 16, 2015 at 08:23:13AM -0400, Haines Brown wrote:
> Sorry for this elementary question. I want to do sequential copies with
> a command like this: $ cp --backup=t  file .../destination/file. When
> periodically run it produces file, file.~1~, file.~2~, etc.
> 
> How do I get rid of the "~" so that the backups are file.1, file.2,
> etc.? 

If you are familiar with shell scripts, you can use a 'for' loop:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
for i in 1 2 3 ; do
	mv file.~${i}~ file.${i}
done
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

You don't have to put each number into the 'for' loop yourself;
with e.g. 17 files, you can write:

for i in `seq 1 17`; do
	...
done


Reply to: