I'm wondering if anyone knows of a nice way to partially duplicate (hard link) files between two directory structures?

My current fall back is a script invoked by cron.

As background:

I ask since I have two groups who both need to access a body of files in a directory structure served via HTTP using Tomcat. A privileged group may access all the files and a less privileged group may only access a "public" subset. These sets are not aligned to particular directories but the different class of file can be identified by their naming convention (but not extension).

Therefore my current idea is to serve two separate directories, one containing only private (possibly password protected) and the other containing public. Then to run some periodic process whereby I create hardlinks from the public files so they appear in the private directories for the convienence of the privileged users. I choose to link in that direction since it's more important that the file is available immediately for the unprivileged users. (priv = admin, unpriv = regular user)

I hope that makes sense. I'll try to clarify if anyone has any questions.


I would use symbolic links.

You could use this Bash script:

ln -s $1 $2/$(basename $1)

with something like these two commands:

find unpriv_criteria -exec ./linkscript {} /unpriv/dir \; 
find priv_criteria -exec ./linkscript {} /priv/dir \;
| improve this answer | |
  • Why do you recommend soft links? I was prefering hardlinks since I won't have to configure Tomcat to follow soft links. In addition it would afford me the luxury of being able to remove files from the public directory without removing it from the private directory. Hope that makes sense? – Tom Duckering Jan 14 '10 at 6:43
  • Here is a discussion of hard and symbolic links: serverfault.com/questions/10543/… – Paused until further notice. Jan 14 '10 at 9:18
  • Thanks for the link. I know the difference and the pros/cons but was wondering why you explicitly recommended using soft links. – Tom Duckering Jan 14 '10 at 9:27

Something like what Dennis proposed would work in a cron job or similar.

If this were linux, I would point you at inotify which would allow you to eliminate the cron job and latency from hardlinks reflecting the original directory.

This doesn't appear to exist under Solaris, however.

If the hardlinks are not too critical, a cron job will probably do just fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.