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

Re: find and copy



On 9/3/13, Craig L. <craig@gtek.biz> wrote:
> On Sun, Sep 01, 2013 at 11:26:07AM +1000, Zenaan Harkness wrote:
>> On 9/1/13, Craig L. <craig@gtek.biz> wrote:
>> >> but evidently not quite ...
>> >
>> >    find /var/lib/postgresql/9.1/backup -mmin -60 -a -iname '*.sql' \
>> >    -execdir cp '{}' /var/data.backup/ ';'
>> >
>> > copies the file to /var/data.backup/dump_08-31-13.sql just fine.
>>
>> It is evident that you are achieving part of what you want.
>>
>> It is evident (since you are asking a question), that you are failing
>> to achieve the other part of what you want. It was unnecessary to have
>> pointed it out, so apologies for that.
>
> That was my reason for stating it the way I did, to show that I could do
> it,
> but only I did not want my file renamed in the process.

It seems I was a bit cavalier on more than one count. My apologies.

>> Actually, what you want I think is independent of stdout, as in, you
>> perhaps could use xargs
>
> I think so too.

>> >> I'm not familiar with -exec option.
>> >
>> > With all due respect, follow your advice: man find and search for
>> > -exec.
>>
>> With all due respect, _you_ are the one seeking assistance. I tried to
>> point you in a direction I knew about and thought might be useful to
>> you. It is not my job to come up with the perfect solution for you, so
>
> Agreed, but the suggestion you first offered (formatted shell output) seemed
> to
> have nothing to do with my goal of command execution. Then you mentioned
> ignorance at the action I was trying to use, so I offered you the same help
> you
> offered me: read the man page. I was not trying to offend you and apologies
> if
> you were. FWIW, I always go to the man page first. After all they've been
> around a lot longer that Google has. Or Debian for that matter.

:)

>> > I would still like to know how to do it as a find action if anyone
>> > has suggestions.
>>
>> I don't. But |xargs is how I would do it, eg:
>>
>> find /var/lib/postgresql/9.1/backup -mmin -60 -a -iname '*.sql' -printf
>> "blah" \
>> | xargs cp '{}' /var/data.backup/
>
> Actaully I considered xargs, but I am very lacking in knowledge
> of it, and the man page did not offer a solution (that I could see)
> either. Your suggestion included here will not work, nor will your
> follow-up suggestion (although the suggestions are appreciated).

Actually, a bit of tweaking and it will work.

> Both seem to be trying to copy the string '{}' and the directory
> /var/data.backup/ to the directory name that is being piped to
> xargs, the name of the found file in this case, which is how I
> understand xargs to funtion. Regardless, I get the same error to
> both:
>
>    "cp: target `dump_08-31-13.sql' is not a directory"

Ah yes, well then an argument to cp should do it:
... | xargs cp -t /var/data.backup/

ought to do the job. And you can test first with the following:
... | xargs echo cp -t /var/data.backup/
            ^^^^

Cheers :)
Zenaan


Reply to: