tags:

views:

95

answers:

5

Hi,

I am facing a copy command problem while executing shell script in RHEL 5.

executed command is

cp -fp /fir1/dir2/*/bin/file1 `find . -name file1 -print`

error is

cp: Target ./6e0476aec9667638c87da1b17b6ccf46/file1 must be a directory

Would you please throw some ideas why it would be failing?

Thanks Robert.

+1  A: 

You cannot copy multiple multiple files to a file, only to a directory, i.e.

cp file1 file2 file2 file4 

is not possible, you need

cp file1 file2 file2 dir1
Drakosha
Thank you all for your comments. I got the point. I will go and change the code accordingly.
Robo
+3  A: 

You can't copy many files to one location unless that location is a directory.

cp should be used thusly: cp sourcefile destinationfile or cp source1 source2 destinationdir.

Borealid
+4  A: 

When cp is called with more than two filenames as arguments, it treats the last one as a target directory, and copies all the files named in the other arguments into that target directory. So, for example,

cp file1 file2 dir3

will create dir3/file1 and dir3/file2. It seems that in your case, the pattern /fir1/dir2/*/bin/file1 matches more than one filename, so cp is trying to treat the result of find as a target directory - which it isn't - and failing.

David Zaslavsky
+2  A: 

As the others said you cannot copy multiple files to one file using cp. On the other hand, if you want to append the content of multiple files together into one destination file you can use cat.

For instance:

cat file1 file2 file3 > destinationfile
nico
+2  A: 

Hi Robert,

it is hard to answer without knowing what you are trying to achieve.

If, for example, you want to copy all files named "file1" within a directory structure to a target place /tmp, building the same directory structure there, this command will do the trick:

cd /dir1/dir2
find . -name file1 | cpio -pvd /tmp
nhnb