Q: copy directory (containing links) as directory (as files)

Q: copy directory (containing links) as directory (as files)

Post by zhou » Sat, 01 Feb 2003 01:05:05



Hi,

On HP-UX, I have two directories: Parent and Child, where Child contains a list of links pointing files elsewhere.
I did a "cp -R .../Parent/child .../newChild", where newChild is a sub-directory to be created somewhere else.
What I got was newChild also containing all the links, is there a way to get all the files instead?

If I go into child directory, and "cp * ....", then I got files (not links). I guess if you copy a directory,
soft links are preserved? Is this a HP-UX implementation or a Unix thing?

Thanks.

Yan

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by Paul Hand » Sat, 01 Feb 2003 02:04:13



> Hi,

> On HP-UX, I have two directories: Parent and Child, where Child contains a
> list of links pointing files elsewhere. I did a "cp -R .../Parent/child
> .../newChild", where newChild is a sub-directory to be created somewhere
> else. What I got was newChild also containing all the links, is there a
> way to get all the files instead?

> If I go into child directory, and "cp * ....", then I got files (not
> links). I guess if you copy a directory, soft links are preserved? Is this
> a HP-UX implementation or a Unix thing?

> Thanks.

> Yan

Hi,

I'm not sure if it's specific to Unix or HP-UX.

However, in the past, i've avoided it by using tar into a pipe.

Imagine you want to copy dir1 and it's contents to dir2.

dir2 will end up in the directory parent2. Try this.....

tar cf - dir1 | (cd <path to parent2>; tar xf -)

This tells tar to send it's output to the stdout stream (the first -), which
is then piped (the | ) to the compound command in brackets.  That tells the
system to change to the target directory and then tells tar to extract from
stdin (the second -).

This copies everything, including links, correctly, and doesn't use any disk
space other than the target.

HTH,

Paul

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by zhou » Sat, 01 Feb 2003 02:30:02


I tried this. But I still get all the links (as long as the source directory contains links).
Any way to copy the files pointed to by those links (not copying links)?

Yan



> > Hi,

> > On HP-UX, I have two directories: Parent and Child, where Child contains a
> > list of links pointing files elsewhere. I did a "cp -R .../Parent/child
> > .../newChild", where newChild is a sub-directory to be created somewhere
> > else. What I got was newChild also containing all the links, is there a
> > way to get all the files instead?

> > If I go into child directory, and "cp * ....", then I got files (not
> > links). I guess if you copy a directory, soft links are preserved? Is this
> > a HP-UX implementation or a Unix thing?

> > Thanks.

> > Yan

> Hi,

> I'm not sure if it's specific to Unix or HP-UX.

> However, in the past, i've avoided it by using tar into a pipe.

> Imagine you want to copy dir1 and it's contents to dir2.

> dir2 will end up in the directory parent2. Try this.....

> tar cf - dir1 | (cd <path to parent2>; tar xf -)

> This tells tar to send it's output to the stdout stream (the first -), which
> is then piped (the | ) to the compound command in brackets.  That tells the
> system to change to the target directory and then tells tar to extract from
> stdin (the second -).

> This copies everything, including links, correctly, and doesn't use any disk
> space other than the target.

> HTH,

> Paul

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by Paul Hand » Sat, 01 Feb 2003 02:47:20



> I tried this. But I still get all the links (as long as the source
> directory contains links). Any way to copy the files pointed to by those
> links (not copying links)?

> Yan




>> > Hi,

>> > On HP-UX, I have two directories: Parent and Child, where Child
>> > contains a list of links pointing files elsewhere. I did a "cp -R
>> > .../Parent/child .../newChild", where newChild is a sub-directory to be
>> > created somewhere else. What I got was newChild also containing all the
>> > links, is there a way to get all the files instead?

>> > If I go into child directory, and "cp * ....", then I got files (not
>> > links). I guess if you copy a directory, soft links are preserved? Is
>> > this a HP-UX implementation or a Unix thing?

>> > Thanks.

>> > Yan

>> Hi,

>> I'm not sure if it's specific to Unix or HP-UX.

>> However, in the past, i've avoided it by using tar into a pipe.

>> Imagine you want to copy dir1 and it's contents to dir2.

>> dir2 will end up in the directory parent2. Try this.....

>> tar cf - dir1 | (cd <path to parent2>; tar xf -)

>> This tells tar to send it's output to the stdout stream (the first -),
>> which
>> is then piped (the | ) to the compound command in brackets.  That tells
>> the system to change to the target directory and then tells tar to
>> extract from stdin (the second -).

>> This copies everything, including links, correctly, and doesn't use any
>> disk space other than the target.

>> HTH,

>> Paul

Whoops, sorry - I read what I thought you were asking instead of the real
question.  Most times I cam up against this, people needed to keep the
links.

Have you tried cp with "-L" option?  This should dereference links.
So, cp -RL source target

Paul

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by zhou » Sat, 01 Feb 2003 03:40:19


No, cp -R only copies links.
cp in my shell bash does not have -L option.

Yan



> > I tried this. But I still get all the links (as long as the source
> > directory contains links). Any way to copy the files pointed to by those
> > links (not copying links)?

> > Yan




> >> > Hi,

> >> > On HP-UX, I have two directories: Parent and Child, where Child
> >> > contains a list of links pointing files elsewhere. I did a "cp -R
> >> > .../Parent/child .../newChild", where newChild is a sub-directory to be
> >> > created somewhere else. What I got was newChild also containing all the
> >> > links, is there a way to get all the files instead?

> >> > If I go into child directory, and "cp * ....", then I got files (not
> >> > links). I guess if you copy a directory, soft links are preserved? Is
> >> > this a HP-UX implementation or a Unix thing?

> >> > Thanks.

> >> > Yan

> >> Hi,

> >> I'm not sure if it's specific to Unix or HP-UX.

> >> However, in the past, i've avoided it by using tar into a pipe.

> >> Imagine you want to copy dir1 and it's contents to dir2.

> >> dir2 will end up in the directory parent2. Try this.....

> >> tar cf - dir1 | (cd <path to parent2>; tar xf -)

> >> This tells tar to send it's output to the stdout stream (the first -),
> >> which
> >> is then piped (the | ) to the compound command in brackets.  That tells
> >> the system to change to the target directory and then tells tar to
> >> extract from stdin (the second -).

> >> This copies everything, including links, correctly, and doesn't use any
> >> disk space other than the target.

> >> HTH,

> >> Paul
> Whoops, sorry - I read what I thought you were asking instead of the real
> question.  Most times I cam up against this, people needed to keep the
> links.

> Have you tried cp with "-L" option?  This should dereference links.
> So, cp -RL source target

> Paul

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by Bill Marcu » Sat, 01 Feb 2003 06:48:45


On Thu, 30 Jan 2003 11:05:05 -0500, zhou

> Hi,

> On HP-UX, I have two directories: Parent and Child, where Child

+>contains a list of links pointing files elsewhere.
Quote:> I did a "cp -R .../Parent/child .../newChild", where newChild is a

+>sub-directory to be created somewhere else.
Quote:> What I got was newChild also containing all the links, is there a way

+>to get all the files instead?
Quote:

> If I go into child directory, and "cp * ....", then I got files (not

+>links). I guess if you copy a directory,
Quote:> soft links are preserved? Is this a HP-UX implementation or a Unix thing?

Did you RTFM?
In Debian Linux:
      -r     copy recursively, non-directories as files WARNING:
              use -R instead when you might  copy  special  files
              like FIFOs or /dev/zero
 
 
 

Q: copy directory (containing links) as directory (as files)

Post by Chris Coyl » Sat, 01 Feb 2003 06:51:27




> tar cf - dir1 | (cd <path to parent2>; tar xf -)

Im guessing the OP was talking about symbolic links, in which case you need -h as in:

tar cfh - dir1 | ...

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by Chris Coyl » Sat, 01 Feb 2003 12:30:24




> On Thu, 30 Jan 2003 11:05:05 -0500, zhou

>> Hi,

>> On HP-UX, I have two directories: Parent and Child, where Child
> +>contains a list of links pointing files elsewhere.
>> I did a "cp -R .../Parent/child .../newChild", where newChild is a

[...]

Quote:

> Did you RTFM?
> In Debian Linux:
>       -r     copy recursively, non-directories as files WARNING:
>               use -R instead when you might  copy  special  files like
>               FIFOs or /dev/zero

I wondered about that too, but when I RTFM on the Solaris and HPUX boxes at work,
concerning the -r option, it only talked about reading pipes, nothing
about following symbolic links, which I guess is what OP is asking about.
 
 
 

Q: copy directory (containing links) as directory (as files)

Post by zhou » Sat, 01 Feb 2003 23:02:04


here is part of the man page on cp:

              With the -R and -r options, in addition to regular files and
              directories, cp also copies FIFOs, character and block device
              files and symbolic links.  Only #ifdef B1 users with mknod
              privilege #else superusers #endif B1 can copy device files.
              All other users get an error.  Symbolic links are copied so
              the target points to the same location that the source did.

As you can see, HP-UX cp preserves symbolic links.
Is there a way to force it to dereference links while coping directory tree?

Yan




> > On Thu, 30 Jan 2003 11:05:05 -0500, zhou

> >> Hi,

> >> On HP-UX, I have two directories: Parent and Child, where Child
> > +>contains a list of links pointing files elsewhere.
> >> I did a "cp -R .../Parent/child .../newChild", where newChild is a

> [...]

> > Did you RTFM?
> > In Debian Linux:
> >       -r     copy recursively, non-directories as files WARNING:
> >               use -R instead when you might  copy  special  files like
> >               FIFOs or /dev/zero

> I wondered about that too, but when I RTFM on the Solaris and HPUX boxes at work,
> concerning the -r option, it only talked about reading pipes, nothing
> about following symbolic links, which I guess is what OP is asking about.

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by zhou » Sat, 01 Feb 2003 23:12:47


tar cfh - dir1 | ... worked. It follows the links

Thanks, Chris!


> On Thu, 30 Jan 2003 11:05:05 -0500, zhou

> > Hi,

> > On HP-UX, I have two directories: Parent and Child, where Child
> +>contains a list of links pointing files elsewhere.
> > I did a "cp -R .../Parent/child .../newChild", where newChild is a
> +>sub-directory to be created somewhere else.
> > What I got was newChild also containing all the links, is there a way
> +>to get all the files instead?

> > If I go into child directory, and "cp * ....", then I got files (not
> +>links). I guess if you copy a directory,
> > soft links are preserved? Is this a HP-UX implementation or a Unix thing?

> Did you RTFM?
> In Debian Linux:
>       -r     copy recursively, non-directories as files WARNING:
>               use -R instead when you might  copy  special  files
>               like FIFOs or /dev/zero

 
 
 

Q: copy directory (containing links) as directory (as files)

Post by William Par » Sun, 02 Feb 2003 08:58:13



> No, cp -R only copies links.
> cp in my shell bash does not have -L option.

'cp' is not part of shell.  It is one of system commands, ie. /bin/cp.
If you can't de-reference the symbolic links, then copy one by one.

--

Linux solution for data management and processing.

 
 
 

1. copying a directory structure with a particular file in directories below

Hello,
I need some help/advise on how to copy a directory structure with a
particular file in directories below the start directory.

Let's say I have many text files [*.txt] with many data files and other
files [*.data, *.*]
The directory I want to copy across to another area with only the text
files but which also retains the directory structure.

i.e.,

[root_directory]
 |__[data]
       |__[directory_1]
       |__[direcotry_2]
       |    |__[directory_2.1]
       |
       |__[directory_3]
       |
       |__[directory_N]

I want to copy the directory [data] to another area with just the *.txt
files but retain the directory structure.

I tried to do this

cp -r `find /[root_directory]/[data] -name "*.txt"` .

NOTE: The above when I include the square brackets is meant to
represent the full name of the
directory and is not to be confused with anything else.

cp -r `find /root_directory/data/ -name "*.txt"` .

When doing this, all I get is the *.txt files without the directory
structure. If the *.txt files have the same name it will cause
problems. So I can copy the directory structure it would be great.

I hope you can understand the issue/problem statement from my
explanation.
If you have any questions please ask me.

Thanks,
ROuNIN

2. Help! Needed: RZ and SZ binaries for SPARC SunOS 5.4

3. Read strings from one file and search for them in a directory containing htm files

4. Security Manual

5. how to copy directory and sub-directory

6. SATA

7. allow apache to copy files from /tmp to a file-directory under php4

8. New linux site - for developers only

9. Problem listing directories containing .htaccess files

10. How to tell if directory contains files?

11. Q: Copying directories that include hard links

12. Finding all files in a directories tree which contain a string

13. Q: Copying directories that include hard links