LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-13-2011, 04:26 AM   #1
fergus
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Rep: Reputation: Disabled
Question about syntax for cp --parents


Well - I just joined LinuxQuestions.org and find no Forum specific to command-line syntax questions, so I'll post it here. Please put me right if I want to go elsewhere. Here is the question. Thank you!

I can use
cp -vr --parents /a/b/c/this /x/y
to create a directory /x/y/a/b/c/this containing this and everything under this.

But how could I create a directory x/y/b/c/this (ie omitting a)? I could MOVE to /a/ and then use
cp -vr --parents b/c/this /x/y
but I really don't want to do the MOVE (and can think of circumstances where I might not be able to).

I'm really looking for something exactly similar to the
tar -C DIRECTORY
switch that allows one to make a virtual move to the directory DIRECTORY before commencing the tar operation.

Thank you!

Fergus
 
Old 06-13-2011, 05:10 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
Why do you use --parents ? This does not copy anything from the parent directories, it merely prepends the path to the copied files.
If all you want is the contents of this, then omit the --parents.

If you really want the path prepended without a then you will have to change directory (cd) to a first.

MOVE is not a command, mv is a command and it basically copies files then deletes the originals.
So you could use a second command that moves b/c/this directly to y and then deletes a

Code:
cp -vr --parents /a/b/c/this /x/y
mv /x/y/a/b /x/y; rm -r /x/y/a
But it would be easier to do this

Code:
cd /a; cp -vr --parents b/c/this /x/y

Last edited by smoker; 06-13-2011 at 05:20 AM.
 
Old 06-13-2011, 05:48 AM   #3
fergus
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
>> Why do you use --parents ?

Because I do want to prepend the path.

>> MOVE is not a command

Yeah, I know, sorry, I just wanted to emphasize how much I didn't want to do this. Bad choice of emphasis by me.

>> But it would be easier to do this:
>> cd /a; cp -vr --parents b/c/this /x/y

Yes, as I thought. What a pain. But thanks. An analogue to the "tar -C" switch would have been so handy!

Best,

Fergus
 
Old 06-13-2011, 05:54 AM   #4
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
Try this..
tar cf - /a/b | ( cd /x/y; tar xfp -)
I haven't tested it.. But it can be modified to your need I believe.
 
Old 06-13-2011, 07:01 AM   #5
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
As a general rule, if the switch you want isn't listed in the man page, then there is no such switch. The beauty of *nix is that many small tools can be made to work together. Or you can create your own !
 
Old 06-14-2011, 12:45 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,295

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
For safety, instead of
Code:
cd /a; cp -vr --parents b/c/this /x/y
I'd do
Code:
cd /a && cp -vr --parents b/c/this /x/y
thus we only do cp if cd worked ok....
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What is the syntax of this question? raviteja_s Linux - Networking 1 10-07-2010 11:34 PM
If...then...else syntax question kaplan71 Linux - Software 8 10-14-2009 10:32 PM
question about good distro for old comp and non tech parents SSJGoku Linux - Distributions 2 05-03-2009 04:47 AM
XML question multiple parents for child element pld Programming 1 03-17-2005 02:14 PM
Syntax question satimis Linux - Newbie 9 09-23-2004 07:47 AM


All times are GMT -5. The time now is 12:17 PM.

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