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
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
- 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
Here's what I tried just now.
#
# 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
- #
- # 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
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.
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$
- 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$
Strong with this one, the sudo is.