Koozali.org: home of the SME Server

How to recursively create hard links?

Offline kevinb

  • *
  • 237
  • +0/-0
How to recursively create hard links?
« on: November 16, 2008, 06:48:59 AM »
Hello everyone,

I have a general Linux question and since SME is my first venture into Linux …. I do not know where else to go.

I have a directory structure
/a/b/c/1
/a/b/c/2/4
/a/b/c/3/5/6

I would like to copy the relative directories only starting from “/1/2/3" and then create hard links to the files in the directories. So I would have:
/x/1
/x/2/4
/x/3/5/6

With only hardlinks.

How can I do this from the CLI (via a cron job, the directories and files will be changing daily)?

Thank you in advance for your help.

Kevin

Offline m

  • *****
  • 276
  • +0/-0
  • Peet
Re: How to recursively create hard links?
« Reply #1 on: November 16, 2008, 01:28:49 PM »
try rsync with the --dest-link option, something like this:

rsync -a --link-dest=/a/b/c /a/b/c/ /x

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: How to recursively create hard links?
« Reply #2 on: November 17, 2008, 01:12:51 AM »
I have a directory structure
/a/b/c/1
/a/b/c/2/4
/a/b/c/3/5/6

I would like to copy the relative directories only starting from “/1/2/3" and then create hard links to the files in the directories. So I would have:
/x/1
/x/2/4
/x/3/5/6

With only hardlinks.

Alternatively:

cd /a/b/c
find . -type d | cpio -dp /x
find . -type f -exec ln {} /x/{} \;

Offline kevinb

  • *
  • 237
  • +0/-0
Re: How to recursively create hard links?
« Reply #3 on: November 17, 2008, 07:47:49 PM »
Thanks for the suggestions everyone.

I just discovered that when you change the permission on a hard link it changes the permissions for all the hard links. No good for me. I will use rync and copy files.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: How to recursively create hard links?
« Reply #4 on: November 17, 2008, 10:44:29 PM »
I just discovered that when you change the permission on a hard link it changes the permissions for all the hard links. No good for me. I will use rync and copy files.

Links are just directory entries. The permissions apply to the files themselves, not to the various directory entries which reference the file.

Offline kevinb

  • *
  • 237
  • +0/-0
Re: How to recursively create hard links?
« Reply #5 on: November 20, 2008, 11:18:09 PM »
That would explain it, thanks.

I am now pursuing another method. I am searching each file for a string and then copying these files to another folder. I can find the files but have not been able to pass the output to "cp" or "rsync". I have gotten this to work:

find <source> -name '*<file name string>*' -print | xargs grep -lirs '<text string 1>' /dev/null

This gives me a list of all the files that have <file name string> in the file name and contain <text string 1>.

  • How can I have it find all the files that contain <text string 1> or <text string 2>?
  • How can I have the command copy these files to another folder?

Thank you very much for your help. I realize that my question is out of the context of this forum and I appreciate the time spent to review this.

Kevin