PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > how can I combine 'find' and 'cp' command ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

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

Réponse
 
LinkBack Outils de la discussion
Vieux 28/10/2007, 01h20   #1
tryhard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how can I combine 'find' and 'cp' command ?

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.

  Réponse avec citation
Vieux 28/10/2007, 01h40   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

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.
  Réponse avec citation
Vieux 28/10/2007, 02h24   #3
tryhard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

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 ?
!!

  Réponse avec citation
Vieux 28/10/2007, 02h47   #4
Wayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

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 ?
> !!
>


$ find . \( -type d -name destiny -prune \) -o -name "*.txt" -exec cp {} ./destiny/ \;
  Réponse avec citation
Vieux 28/10/2007, 03h19   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

On 2007-10-28, tryhard <jh3ang@gmail.com> 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 ?
> !!
>

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/

  Réponse avec citation
Vieux 28/10/2007, 03h54   #6
Wayne
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

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 ?
>> !!
>>

>
> $ 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
  Réponse avec citation
Vieux 28/10/2007, 11h44   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

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 ?
>>> !!
>>>

>>
>> $ 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
  Réponse avec citation
Vieux 28/10/2007, 11h45   #8
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

2007-10-27, 22:19(-04), Bill Marcum:
> On 2007-10-28, tryhard <jh3ang@gmail.com> 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 ?
>> !!
>>

> 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
  Réponse avec citation
Vieux 30/10/2007, 07h00   #9
kjteoh@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how can I combine 'find' and 'cp' command ?

hmm #mkdir destiny

On Oct 28, 8:20 am, tryhard <jh3...@gmail.com> 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.



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h02.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16846 seconds with 17 queries