LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   cp command problem..... unexpected result (http://www.linuxquestions.org/questions/linux-general-1/cp-command-problem-unexpected-result-54445/)

hamster 04-10-2003 03:59 PM

cp command problem..... unexpected result
 
I have this structure:

tempdir3
tempdir2
|--tempfile1
|--tempfile2
|--tempfile3
|
|--tempdir1
......|--tempfile1
.....|--tempfile2
.....|--tempfile3

I want to copy /tempdir2/tempdir1/tempfile1 into tempdir3...

ie I want the stucture /tempdir2/tempdir1/tempfile1 in /tempdir3 not just the file tempfile1... :(

I used the command:
cp -p /tempdir2/tempdir1/tempfile1 tempdir3
This only copies tempfile1 into tempdir3. I want the structure from /tempdir2 onwards to go in there. Grrr!

It's like as if I'm just doing:
cp /tempdir2/tempdir1/temp1file1 tempdir3...

I'm using Redhat 8 and the man page isn't really clear on this. Any ideas?

glock27linux 04-10-2003 04:44 PM

If I read you correctly, you'd like to see the following as a end result:

./tempdir3/tempdir2/tempdir1/tempfile1

One of the quickest ways I can see doing that is:

tar -cpf newcopy.tar tempdir2/tempdir1/tempfile1
tar -C tempdir3 -xpf newcopy.tar

that'll create ./tempdir3/tempdir2/tempdir1/tempfile1 for you, and only that. Using cp recursively would grab other files as well as tempfile1.
This help?

hamster 04-10-2003 04:57 PM

glock27linux,

Yep, thats what I'm trying to do. The exerise (Sam's 24 hour book actually) was trying to show that you could pluck just one of the 3 files outta there without moving the whole lot... because that would have been easy, ie:

cp -r tempdir2/tempdir1 tempdir3 :)

I see you tar the structure and file and extract it inside tempdir3 instead. Another way. :) I see you use the -p parameter there too and that's what I had hoped would work with my cp line.

Thanks.


All times are GMT -5. The time now is 02:26 AM.