how can I combine "find" and "cp" command ?

how can I combine "find" and "cp" command ?

am 28.10.2007 02:20:04 von jaehwang

How are you ? Please give me your advice *.*;

I was trying to find any text files and copy those to the specific
folder.
I used this:

$find . -name "*.txt" -exec "cp {} ./destiny/" \;

find: cp ./1.txt ./destiny/: No such file or directory
find: cp ./a/2.txt ./destiny/: No such file or directory
find: cp ./a/aa/3.txt ./destiny/: No such file or directory
find: cp ./b/4.txt ./destiny/: No such file or directory

is there any way to solve this ?
text files should be copied to the destiny folder.

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 02:24:55 von jaehwang

output looks like this:
I tried it without quoting around 'cp'

$ find . -name "*.txt" -exec cp {} ./destiny/ \;
cp: ./destiny/1.txt and ./destiny/1.txt are identical (not copied).
cp: ./destiny/2.txt and ./destiny/2.txt are identical (not copied).
cp: ./destiny/3.txt and ./destiny/3.txt are identical (not copied).
cp: ./destiny/4.txt and ./destiny/4.txt are identical (not copied).

what does it mean ? :(
help !!

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 02:40:47 von Icarus Sparry

On Sat, 27 Oct 2007 17:20:04 -0700, tryhard wrote:

> How are you ? Please give me your advice *.*;
>
> I was trying to find any text files and copy those to the specific
> folder.
> I used this:
>
> $find . -name "*.txt" -exec "cp {} ./destiny/" \;
>
> find: cp ./1.txt ./destiny/: No such file or directory find: cp
> ./a/2.txt ./destiny/: No such file or directory find: cp ./a/aa/3.txt
> ./destiny/: No such file or directory find: cp ./b/4.txt ./destiny/: No
> such file or directory
>
> is there any way to solve this ?
> text files should be copied to the destiny folder.

You are quoting too much. The message tells you that there is no command

cp 1.txt ./destiny/

(that is one "word", 19 characters long, starting with "c" and ending
with "/").

Remove the quotes.

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 02:47:28 von wayne

tryhard wrote:
> output looks like this:
> I tried it without quoting around 'cp'
>
> $ find . -name "*.txt" -exec cp {} ./destiny/ \;
> cp: ./destiny/1.txt and ./destiny/1.txt are identical (not copied).
> cp: ./destiny/2.txt and ./destiny/2.txt are identical (not copied).
> cp: ./destiny/3.txt and ./destiny/3.txt are identical (not copied).
> cp: ./destiny/4.txt and ./destiny/4.txt are identical (not copied).
>
> what does it mean ? :(
> help !!
>

$ find . \( -type d -name destiny -prune \) -o -name "*.txt" -exec cp {} ./destiny/ \;

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 03:19:21 von Bill Marcum

On 2007-10-28, tryhard wrote:
> output looks like this:
> I tried it without quoting around 'cp'
>
> $ find . -name "*.txt" -exec cp {} ./destiny/ \;
> cp: ./destiny/1.txt and ./destiny/1.txt are identical (not copied).
> cp: ./destiny/2.txt and ./destiny/2.txt are identical (not copied).
> cp: ./destiny/3.txt and ./destiny/3.txt are identical (not copied).
> cp: ./destiny/4.txt and ./destiny/4.txt are identical (not copied).
>
> what does it mean ? :(
> help !!
>
It means just what it says: After copying other files into ./destiny, it tries
to copy the files that are in ./destiny. Try this:
find . -name destiny -prune -o -name "*.txt" -exec cp {} ./destiny/

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 03:54:07 von wayne

Wayne wrote:
> tryhard wrote:
>> output looks like this:
>> I tried it without quoting around 'cp'
>>
>> $ find . -name "*.txt" -exec cp {} ./destiny/ \;
>> cp: ./destiny/1.txt and ./destiny/1.txt are identical (not copied).
>> cp: ./destiny/2.txt and ./destiny/2.txt are identical (not copied).
>> cp: ./destiny/3.txt and ./destiny/3.txt are identical (not copied).
>> cp: ./destiny/4.txt and ./destiny/4.txt are identical (not copied).
>>
>> what does it mean ? :(
>> help !!
>>
>
> $ find . \( -type d -name destiny -prune \) -o -name "*.txt" -exec cp {} ./destiny/ \;

What a dumb suggestion! Actually you should do this:

$ find . -name '*.txt' -print0 | xargs -0 cp -ft ./destiny/

This depends on your having the Gnu version of cp available.

-Wayne

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 11:44:32 von Stephane CHAZELAS

2007-10-27, 22:54(-04), Wayne:
> Wayne wrote:
>> tryhard wrote:
>>> output looks like this:
>>> I tried it without quoting around 'cp'
>>>
>>> $ find . -name "*.txt" -exec cp {} ./destiny/ \;
>>> cp: ./destiny/1.txt and ./destiny/1.txt are identical (not copied).
>>> cp: ./destiny/2.txt and ./destiny/2.txt are identical (not copied).
>>> cp: ./destiny/3.txt and ./destiny/3.txt are identical (not copied).
>>> cp: ./destiny/4.txt and ./destiny/4.txt are identical (not copied).
>>>
>>> what does it mean ? :(
>>> help !!
>>>
>>
>> $ find . \( -type d -name destiny -prune \) -o -name "*.txt" -exec cp {} ./destiny/ \;
>
> What a dumb suggestion! Actually you should do this:
>
> $ find . -name '*.txt' -print0 | xargs -0 cp -ft ./destiny/
>
> This depends on your having the Gnu version of cp available.
[...]

And find and xargs. -print0, -0, -t are GNU extensions. And you
probably want to add the -r option to xargs (another GNU
extension) to prevent an error message if there's not txt file.

But that doesn't prevent find to find files in ./destiny.

A POSIX solution:

mv destiny .. &&
find . -name '*.txt' -type f -exec sh -c '
exec cp -f "$@" ../destiny' inline {} + &&
mv ../destiny .

--
Stéphane

Re: how can I combine "find" and "cp" command ?

am 28.10.2007 11:45:57 von Stephane CHAZELAS

2007-10-27, 22:19(-04), Bill Marcum:
> On 2007-10-28, tryhard wrote:
>> output looks like this:
>> I tried it without quoting around 'cp'
>>
>> $ find . -name "*.txt" -exec cp {} ./destiny/ \;
>> cp: ./destiny/1.txt and ./destiny/1.txt are identical (not copied).
>> cp: ./destiny/2.txt and ./destiny/2.txt are identical (not copied).
>> cp: ./destiny/3.txt and ./destiny/3.txt are identical (not copied).
>> cp: ./destiny/4.txt and ./destiny/4.txt are identical (not copied).
>>
>> what does it mean ? :(
>> help !!
>>
> It means just what it says: After copying other files into ./destiny, it tries
> to copy the files that are in ./destiny. Try this:
> find . -name destiny -prune -o -name "*.txt" -exec cp {} ./destiny/

The problem with that is that it doesn't copy the files from
../foo/destiny, nor ./bar/destiny

--
Stéphane

Re: how can I combine "find" and "cp" command ?

am 30.10.2007 07:00:13 von kjteoh

hmm #mkdir destiny

On Oct 28, 8:20 am, tryhard wrote:
> How are you ? Please give me your advice *.*;
>
> I was trying to find any text files and copy those to the specific
> folder.
> I used this:
>
> $find . -name "*.txt" -exec "cp {} ./destiny/" \;
>
> find: cp ./1.txt ./destiny/: No such file or directory
> find: cp ./a/2.txt ./destiny/: No such file or directory
> find: cp ./a/aa/3.txt ./destiny/: No such file or directory
> find: cp ./b/4.txt ./destiny/: No such file or directory
>
> is there any way to solve this ?
> text files should be copied to the destiny folder.