Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find and copy

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
hi

I would like to copy files that find command finds somehow. None of this does not work

find less/DH* more/DH* -type f -name "all*.dat" -exec cp "c:\users\"

find less/DH* more/DH* -type f -name "all*.dat" | cpio -pdumv "c:\users\"

how to do properly this?

thanks
oliver
 
Firstly try 'man find', really you ought to RTFM before posting.

To run a command within find use
Code:
find less/DH* -type f -name "all*.dat" -exec cp {} "c:\users\"\;
Note that the -exec has the found file name represented by {} and an escaped semicolon (\;) at the end of the command.
Note also that you cant have more than one path at the start so your script becomes
Code:
for dir in less/DH* more/DH*
do
  find $dir -type f -name "all*.dat" -exec cp {} "c:\users\" \;
done
And the next problem is the way in which Unix understands th e backslash. You need to either quote them with the single quote or escape them. Your code now becomes
Code:
for dir in less/DH* more/DH*
do
  find $dir -type f -name "all*.dat" -exec cp {} 'c:\users\' \;
done
or
Code:
for dir in less/DH* more/DH*
do
  find $dir -type f -name "all*.dat" -exec cp {} "c:\\users\\" \;
done
I assume from the very windows like path at the end you are using some form of Unix like shell on a Windows box. Welcome to the dark side of the force!

Ceci n'est pas une signature
Columb Healy
 
thanks Columb


I use Cygwin and I am very very new in Unix. I read manual every time befor posting but sometimes I can not understand everything so I post question here.
 
columb said:
Note also that you can't have more than one path at the start so your script becomes

???

man page extract:
Code:
find Command

Purpose

       Finds files with a matching expression.

Syntax

       find [ -H | -L ] Path ... [ Expression ]

You can put in as many path specifiers in the find comamnd as you want (and the system/shell can handle)

True that with wildcards, the list of paths to examine can become too large for the shell's commandline buffer.


HTH,

p5wizard
 
you cant have more than one path
Really ? Columb, which flavor of find are you using ?
 
Ooops...

I stand corrected

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top