Best way to symlink all but one file?

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

I need to duplicate a folder which contains the HTML template files for a forum, with the exception of one file which will contain a couple of category-specific alterations. I don't want to edit everything in both places any time I need to make a global alteration, so I'm thinking I can symlink all but this one file. That way I only have to edit one file for global edits, and the category-specific file is the only one I need to edit in both places.

What would be the easiest way to symlink every file in a folder, except for that one file ?
  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Posts: 2700
  • Loc: Somewhere outside the box in Sarasota, FL.

Post 3+ Months Ago

Maybe I am not understanding, but what about symlinking the folder itself?

For example;

/folder_of_files/files

/folder2 -> /folder_of_files/files

Then have a third folder with the specific one;
/folder_of_static_file/file

Then ref folder 1 and folder 3 in the one html document and folder2 and folder 3 in the other?

Another option is to set up rsync
http://www.samba.org/ftp/rsync/rsync.html

Which I believe can be used on the same node without the necessity of scping files from one server to another.

Maybe a better option is csync or unison?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

I'm working around the way the forum software (phpBB3) utilizes HTML templates. I need to keep all of the files within the same folder for each template. Both templates will be on on the same server. (within the same sub-folder)

If I were to go through and symlink each file manually, I'd end up with something like this

Code: [ Select ]
templates/

templates/one/a.html
templates/one/b.html
templates/one/c.html

templates/two/a.html -> ../one/a.html
templates/two/b.html
templates/two/c.html -> ../one/c.html
  1. templates/
  2. templates/one/a.html
  3. templates/one/b.html
  4. templates/one/c.html
  5. templates/two/a.html -> ../one/a.html
  6. templates/two/b.html
  7. templates/two/c.html -> ../one/c.html


Here's what I tried just now.

BASH Code: [ Select ]
#
# Current state of the template directory
#
me@box:~$ mkdir templates
me@box:~$ cd templates
me@box:~/templates$ mkdir one
me@box:~/templates$ touch one/a one/b one/c
me@box:~/templates$ ls one
a  b  c
 
#
# What I tried
#
me@box:~/templates$ ln -s one two
 
#
# Echo into one, cat out two; change is reflected
#
me@box:~/templates$ echo "file a" > one/a
me@box:~/templates$ cat two/a
file a
 
#
# Echo into two, cat out one; change is reflected
#
me@box:~/templates$ echo "file c" > two/c
me@box:~/templates$ cat one/c
file c
 
#
# Try using an editor, thinking it will dereference the symlink and create a copy of the file
# change is still reflected
#
me@box:~/templates$ nano two/b
me@box:~/templates$ cat two/b
file b
me@box:~/templates$ cat one/b
file b
 
#
# Try to copy from one to two, to overwrite symlink with copy of the file
#
me@box:~/templates$ cp one/b two/b
cp: `one/b' and `two/b' are the same file
  1. #
  2. # Current state of the template directory
  3. #
  4. me@box:~$ mkdir templates
  5. me@box:~$ cd templates
  6. me@box:~/templates$ mkdir one
  7. me@box:~/templates$ touch one/a one/b one/c
  8. me@box:~/templates$ ls one
  9. a  b  c
  10.  
  11. #
  12. # What I tried
  13. #
  14. me@box:~/templates$ ln -s one two
  15.  
  16. #
  17. # Echo into one, cat out two; change is reflected
  18. #
  19. me@box:~/templates$ echo "file a" > one/a
  20. me@box:~/templates$ cat two/a
  21. file a
  22.  
  23. #
  24. # Echo into two, cat out one; change is reflected
  25. #
  26. me@box:~/templates$ echo "file c" > two/c
  27. me@box:~/templates$ cat one/c
  28. file c
  29.  
  30. #
  31. # Try using an editor, thinking it will dereference the symlink and create a copy of the file
  32. # change is still reflected
  33. #
  34. me@box:~/templates$ nano two/b
  35. me@box:~/templates$ cat two/b
  36. file b
  37. me@box:~/templates$ cat one/b
  38. file b
  39.  
  40. #
  41. # Try to copy from one to two, to overwrite symlink with copy of the file
  42. #
  43. me@box:~/templates$ cp one/b two/b
  44. cp: `one/b' and `two/b' are the same file


I'm thinking since I symlinked the directory, instead of individual files, I'm not going to be able to replace a "symlinked file" with a real file because the new directory is a symlink and not a real directory.

Now, as I go over "cp --help", I come across a mention of symlinking files instead of copying them.

Now that I try this, I think I've got what I'm looking for.

BASH Code: [ Select ]
me@box:~/templates$ cp -s one/* two
#cp: `two/a': can make relative symbolic links only in current directory
#cp: `two/b': can make relative symbolic links only in current directory
#cp: `two/c': can make relative symbolic links only in current directory
me@box:~/templates$ ls two
me@box:~/templates$ cd two
me@box:~/templates/two$ cp -s ../one/* ./
me@box:~/templates/two$ ls -la
total 8
drwxr-xr-x 2 me me 4096 2010-08-25 20:32 .
drwxr-xr-x 4 me me 4096 2010-08-25 20:28 ..
lrwxrwxrwx 1 me me    8 2010-08-25 20:32 a -> ../one/a
lrwxrwxrwx 1 me me    8 2010-08-25 20:32 b -> ../one/b
lrwxrwxrwx 1 me me    8 2010-08-25 20:32 c -> ../one/c
me@box:~/templates/two$ rm b
me@box:~/templates/two$ cp ../one/b ./
me@box:~/templates/two$ ls -la
total 12
drwxr-xr-x 2 me me 4096 2010-08-25 20:32 .
drwxr-xr-x 4 me me 4096 2010-08-25 20:28 ..
lrwxrwxrwx 1 me me    8 2010-08-25 20:32 a -> ../one/a
-rw-r--r-- 1 me me    7 2010-08-25 20:32 b
lrwxrwxrwx 1 me me    8 2010-08-25 20:32 c -> ../one/c
me@box:~/templates/two$
  1. me@box:~/templates$ cp -s one/* two
  2. #cp: `two/a': can make relative symbolic links only in current directory
  3. #cp: `two/b': can make relative symbolic links only in current directory
  4. #cp: `two/c': can make relative symbolic links only in current directory
  5. me@box:~/templates$ ls two
  6. me@box:~/templates$ cd two
  7. me@box:~/templates/two$ cp -s ../one/* ./
  8. me@box:~/templates/two$ ls -la
  9. total 8
  10. drwxr-xr-x 2 me me 4096 2010-08-25 20:32 .
  11. drwxr-xr-x 4 me me 4096 2010-08-25 20:28 ..
  12. lrwxrwxrwx 1 me me    8 2010-08-25 20:32 a -> ../one/a
  13. lrwxrwxrwx 1 me me    8 2010-08-25 20:32 b -> ../one/b
  14. lrwxrwxrwx 1 me me    8 2010-08-25 20:32 c -> ../one/c
  15. me@box:~/templates/two$ rm b
  16. me@box:~/templates/two$ cp ../one/b ./
  17. me@box:~/templates/two$ ls -la
  18. total 12
  19. drwxr-xr-x 2 me me 4096 2010-08-25 20:32 .
  20. drwxr-xr-x 4 me me 4096 2010-08-25 20:28 ..
  21. lrwxrwxrwx 1 me me    8 2010-08-25 20:32 a -> ../one/a
  22. -rw-r--r-- 1 me me    7 2010-08-25 20:32 b
  23. lrwxrwxrwx 1 me me    8 2010-08-25 20:32 c -> ../one/c
  24. me@box:~/templates/two$
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

I caught what you're saying with rsync this morning Daemonguy. I saw it before, but when I read rsync I thought backups and overkill.

I've pretty much got this issue "working" for the time being, I'm not quite sure how close to your suggestion what I ended up doing was, but I'll definitely check out csync and unison just to see what they are. It usually takes me awhile to understand the capabilities of the tools you suggest. It's as if I'm looking in my toolbox thinking "hammer hammer hammer hammer" and you're pointing out a box that contains an air nailer, air hose, air compressor, extension cord, and nails. :)
  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Posts: 2700
  • Loc: Somewhere outside the box in Sarasota, FL.

Post 3+ Months Ago

:) Doesn't hurt to play with the air hose once in awhile. ;)

In the end, if your solution works, then you found the right one. :)

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.