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

Re: cp output format



On Sat, Jul 18, 2015 at 8:40 PM, The Wanderer <wanderer@fastmail.fm> wrote:
> On 07/18/2015 at 07:18 AM, Wilko Fokken wrote:
>
>> 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
>
> Or just try mmv, from the package of the same name.
>
> mmv "file.~*~' "file.#1"
>
> should do it in this case.
>
> None of this really addresses the original question as I understood it,
> which was how to tell cp to create its backup filenames with a different
> naming pattern - but as far as I've been able to discover there doesn't
> seem to be any way to do that, so workarounds like this are about the
> best that can be done.
>
> (Aside from possibly filing a feature request against coreutils
> upstream, anyway. But the odds of that going anywhere soon seem slim.)

One way to change the odds.

We have the source. The OP could spend just an hour or two making his
own version of cp and install it in his own /bin, or, if he has ~/bin
first in his $PATH, there, to avoid the possibility of collateral
damage.

> --
>    The Wanderer
>
> The reasonable man adapts himself to the world; the unreasonable one
> persists in trying to adapt the world to himself. Therefore all
> progress depends on the unreasonable man.         -- George Bernard Shaw
>

Or learn how to use rsync (as others have mentioned), which would get
him a lot closer to his probable purpose.

-- 
Joel Rees

Be careful when you look at conspiracy.
Arm yourself with knowledge of yourself, as well:
http://reiisi.blogspot.jp/2011/10/conspiracy-theories.html


Reply to: