|
Home > Archive > Unix Shell > May 2007 > is there a cp argument that preserves directory structure
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
is there a cp argument that preserves directory structure
|
|
|
| e.g. file: ./a/b/c/a.txt
I wanna cp file to a another directory, while mkdir'ing a/b/c/ if
neccessary, can that be done?
Regards
| |
| Jean-Rene David 2007-05-23, 1:17 am |
| * Ben [2007.05.23 05:46]:
> e.g. file: ./a/b/c/a.txt
> I wanna cp file to a another directory, while mkdir'ing a/b/c/ if
> neccessary, can that be done?
pax -r -w ./a/b/c/a.txt directory
--
JR
| |
| Kenny McCormack 2007-05-23, 1:18 pm |
| In article <s42dnfTHFtJnRc7bnZ2dnUVZ_q2pnZ2d@magma.ca>,
Jean-Rene David <jrdavid@magma.ca> wrote:
>* Ben [2007.05.23 05:46]:
>
>pax -r -w ./a/b/c/a.txt directory
Not exactly answering the question...
I'm sure a PERL 'solution' is coming soon.
| |
| Ron Hardin 2007-05-23, 1:18 pm |
| Kenny McCormack wrote:
>
> In article <s42dnfTHFtJnRc7bnZ2dnUVZ_q2pnZ2d@magma.ca>,
> Jean-Rene David <jrdavid@magma.ca> wrote:
>
> Not exactly answering the question...
>
> I'm sure a PERL 'solution' is coming soon.
echo ./a/b/c/a.txt | cpio -pdm directory
--
Ron Hardin
rhhardin@mindspring.com
On the internet, nobody knows you're a jerk.
| |
| Jean-Rene David 2007-05-23, 1:18 pm |
| * Kenny McCormack [2007.05.23 12:49]:
> In article <s42dnfTHFtJnRc7bnZ2dnUVZ_q2pnZ2d@magma.ca>,
> Jean-Rene David <jrdavid@magma.ca> wrote:
>
> Not exactly answering the question...
It's portable and does exactly what the OP asked for. In
what way is it not answering the question? Because it
doesn't use cp?
--
JR
| |
| Kenny McCormack 2007-05-23, 1:18 pm |
| In article <nZqdndpZl6DozcnbnZ2dnUVZ_rXinZ2d@magma.ca>,
Jean-Rene David <jrdavid@magma.ca> wrote:
>* Kenny McCormack [2007.05.23 12:49]:
>
>It's portable and does exactly what the OP asked for. In
>what way is it not answering the question? Because it
>doesn't use cp?
Indeed.
What part of 'Is there a *cp* [1] argument that preserves directory structure"
do you not understand?
[1] emphasis mine, Ed.
P.S. Now that someone has provided a cpio 'solution', I'm still holding
out for 'solutions' in perl, Python, and i386 assembler.
| |
| Jean-Rene David 2007-05-23, 1:18 pm |
| * Kenny McCormack [2007.05.23 15:22]:
> What part of 'Is there a *cp* [1] argument that preserves
> directory structure" do you not understand?
I just thought suggesting another tool would be more
productive than the "on-topic" answer, which is "no".
It's certainly more productive than... Well, you know... Ah
never mind.
--
JR [who hadn't used that special keybinding for awhile]
| |
| Allodoxaphobia 2007-05-23, 7:20 pm |
| > Kenny McCormack wrote:
>--
> On the internet, nobody knows you're a jerk.
However, most are suspicious. :-)
| |
| Hanspeter 'Happl' Oberlin 2007-05-23, 7:20 pm |
| In article <1179899201.163021.127730@w5g2000hsg.googlegroups.com>,
Ben <chinese.central@googlemail.com> wrote:
>e.g. file: ./a/b/c/a.txt
>I wanna cp file to a another directory, while mkdir'ing a/b/c/ if
>neccessary, can that be done?
man cp
-R If source_file designates a directory, cp copies the directory and
the entire subtree connected at that point. This option also
causes symbolic links to be copied, rather than indirected through,
and for cp to create special files rather than copying them as nor-
mal files. Created directories have the same mode as the corre-
sponding source directory, unmodified by the process' umask.
Note that cp copies hard linked files as separate files. If you
need to preserve hard links, consider using tar(1), cpio(1), or
pax(1) instead.
--
Gruesse aus der Schweiz
Salutations en provenance de Suisse
Saluti dalla Svizzera
Greetings from Switzerland
Happl
| |
| Barry Margolin 2007-05-24, 1:16 am |
| In article <spam4hp-BD5EA5.21435123052007@individual.de>,
Hanspeter 'Happl' Oberlin <spam4hp@gmail.com> wrote:
> In article <1179899201.163021.127730@w5g2000hsg.googlegroups.com>,
> Ben <chinese.central@googlemail.com> wrote:
>
>
> man cp
>
> -R If source_file designates a directory, cp copies the directory and
> the entire subtree connected at that point. This option also
> causes symbolic links to be copied, rather than indirected through,
> and for cp to create special files rather than copying them as nor-
> mal files. Created directories have the same mode as the corre-
> sponding source directory, unmodified by the process' umask.
>
> Note that cp copies hard linked files as separate files. If you
> need to preserve hard links, consider using tar(1), cpio(1), or
> pax(1) instead.
I don't think that's what he's asking for. He doesn't want to copy an
entire directory, he just wants to copy a single file. But that file is
several directories down from his current directory, and he wants to put
it similarly nested in the destination directory.
As others have pointed out, there are tools that can do this. But cp
doesn't have the ability built into it.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|