Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-10-2003, 04:59 PM   #1
Registered: Apr 2003
Location: Waterford, Ireland
Distribution: Mandrivia 2006.1, Ubuntu 7.10
Posts: 188

Rep: Reputation: 30
cp command problem..... unexpected result

I have this structure:


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?

Last edited by hamster; 04-10-2003 at 05:00 PM.
Old 04-10-2003, 05:44 PM   #2
LQ Newbie
Registered: Nov 2002
Posts: 29

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


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?
Old 04-10-2003, 05:57 PM   #3
Registered: Apr 2003
Location: Waterford, Ireland
Distribution: Mandrivia 2006.1, Ubuntu 7.10
Posts: 188

Original Poster
Rep: Reputation: 30

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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Output the result of a command to a file darkarcon2015 Linux - Newbie 1 09-24-2005 07:29 PM
Unexpected behaviour with the find command dazdaz Linux - General 3 12-15-2004 09:50 PM
BASH Command Result redhatnoob Programming 2 08-19-2004 07:25 PM
MySQL queries from Shell - unexpected result philipz Programming 5 05-04-2004 06:38 PM
Unexpected Behavior (passwd command) Penguin666 Linux - General 3 11-20-2003 12:34 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:11 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration