Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora Support > Archived > gmane.linux.redhat.fedora.general

gmane.linux.redhat.fedora.general gmane.linux.redhat.fedora.general newsgroup archive.


 
 
Thread Tools Search this Thread Display Modes
  #1  
Old 2005-02-14, 06:20 AM CST
Guest
 
Posts: n/a
need help making hard link for a directory tree


I need to mirror a complex directory structure with hard links. Of course the
directories themselves can not be hard linked, but is there a simple way to
create a duplicate directory tree and then make hard links to all of the
files?

The links are to provide ftp access to files in a chrooted area on the same
partition.


Thanks.

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list

  #2  
Old 2005-02-14, 06:40 AM CST
Paul Howarth
Guest
 
Posts: n/a
Re: need help making hard link for a directory tree

fedora-list@jamesplace.net wrote:
> I need to mirror a complex directory structure with hard links. Of course the
> directories themselves can not be hard linked, but is there a simple way to
> create a duplicate directory tree and then make hard links to all of the
> files?
>
> The links are to provide ftp access to files in a chrooted area on the same
> partition.


Try this script. Run it from the top-level directly that you want to
copy-by-linking, after setting the CHROOT value to the full pathname of
the directory you want to create the copy in. This script will only link
regular files, not symlinks, device files etc., but you should be able
to modify it to do that fairly easily if you need to do that.

#!/bin/sh

# TEMPLATE directory is root of tree you want to replicate.
# It should *not* be an absolute pathname.
TEMPLATE=.

# CHROOT is absolute pathname of directory you want to clone the
# template to.
# It must be an absolute pathname and it must not be a subdirectory
# of the template directory.
CHROOT=/path/to/chroot

# Replicate directory structure
find $TEMPLATE -type d -exec mkdir -p $CHROOT/{} \;

# Make hard links to files
find $TEMPLATE -type f -exec ln {} $CHROOT/{} \;



Paul.

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list

  #3  
Old 2005-02-15, 12:30 PM CST
Deron Meranda
Guest
 
Posts: n/a
Re: need help making hard link for a directory tree

On Mon, 14 Feb 2005 08:14:59 -0600, fedora-list@jamesplace.net
<fedora-list@jamesplace.net> wrote:
> I need to mirror a complex directory structure with hard links. Of course the
> directories themselves can not be hard linked,



Actually, you *can* hard-link directories (if root). But it's just
not advisable
unless you are an *expert*. Hard linked directories can cause all kinds of
strangeness, and potentially corrupted filesystems. In addition the meaning
of "." and ".." may be surprising to you, or to some software. [in fact the
"." and ".." directories are in fact just hard links to the real
directory, which the
kernel creates for you automatically.]

See the man page for ln(1), and for link(2).


> but is there a simple way to
> create a duplicate directory tree and then make hard links to all of the
> files?


Many options...

The -l option on the cp(1) command.

Use a gtar-pair with the -H option, like,

gtar -C srcdir -cHf - . | gtar -C destdir -xHpf -

Use rsync, like,

rsync -av /srcdir /destdir

(It's really the -l option on rsync, but the -a implies -l)

Or, if you want symlinks instead of hardlinks, see the
lndir(1) command.


> The links are to provide ftp access to files in a chrooted area on the same
> partition.


Then another option, is to use loopback mounts. That has the advantage in
that files can be added/removed without having to redo link maintenance.

--
Deron Meranda

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list

  #4  
Old 2005-02-15, 01:50 PM CST
Guest
 
Posts: n/a
Re: need help making hard link for a directory tree


This worked brilliantly. I was able to modify the script a little and it works
very well.
I just delete the entire (destination) structure each night, and re-create it
with the script to account for the occasional/rare file rename/delete.

It was hard links to directories that I thought it best to avoid.
This was very helpful.

Thanks much.

===

On Mon February 14 2005 8:31 am, Paul Howarth wrote:
> fedora-list@jamesplace.net wrote:
> > I need to mirror a complex directory structure with hard links. Of course
> > the directories themselves can not be hard linked, but is there a simple
> > way to create a duplicate directory tree and then make hard links to all
> > of the files?
> >
> > The links are to provide ftp access to files in a chrooted area on the
> > same partition.

>
> Try this script. Run it from the top-level directly that you want to
> copy-by-linking, after setting the CHROOT value to the full pathname of
> the directory you want to create the copy in. This script will only link
> regular files, not symlinks, device files etc., but you should be able
> to modify it to do that fairly easily if you need to do that.
>
> #!/bin/sh
>
> # TEMPLATE directory is root of tree you want to replicate.
> # It should *not* be an absolute pathname.
> TEMPLATE=.
>
> # CHROOT is absolute pathname of directory you want to clone the
> # template to.
> # It must be an absolute pathname and it must not be a subdirectory
> # of the template directory.
> CHROOT=/path/to/chroot
>
> # Replicate directory structure
> find $TEMPLATE -type d -exec mkdir -p $CHROOT/{} \;
>
> # Make hard links to files
> find $TEMPLATE -type f -exec ln {} $CHROOT/{} \;
>
>
>
> Paul.


--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list

 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
making a link to an app caoinan General Support 7 2009-01-18 01:54 AM CST
How do you *.tar.gz an entire directory tree. awohld General Support 9 2006-06-11 08:25 PM CDT
Kernel Source Tree Directory Structure Michael Harris Software 3 2006-02-21 04:22 PM CST
Re: need help making hard link for a directory tree Ron Yorston gmane.linux.redhat.fedora.general 0 2005-02-15 12:10 PM CST
print directory tree Daniel Harrison gmane.linux.redhat.fedora.general 9 2005-02-02 12:33 PM CST

Translations (Powered by Powered by Google):
Afrikaans Albanian Arabic Belarusian Bulgarian Catalan Chinese Croatian Czech Danish Dutch English Estonian Filipino Finnish French Galician German Greek Hebrew Hindi Hungarian Icelandic Indonesian Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Taiwanese Thai Turkish Ukrainian Vietnamese Yiddish

All times are GMT -7. The time now is 12:17 AM CDT.

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo



All trademarks, and forum posts in this site are property of their respective owner(s).

FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Rules | Archive | Contact | Founding Members
Designed By Ewdison Then | Powered by vBulletin ©2000-2010, Jelsoft Enterprises Ltd.
FedoraForum is Powered by Open Source Projects and Products
Translated to other languages supported by vB Enterprise Translator 2.3.10