|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 ? ![]() !! |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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/ \; |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|