Score:0

How to create a shadow directory

us flag

I want to create a shadow directory of a directory D. The shadow directory D1 should have the same structure as D, but should not share any nodes with D. Each file in D should be represented by a symlink to that file in D1. The idea is that operations on D1 should never modify D, so that I can freely delete anything in D1 without affecting D. How can I achieve this? I could of course do a simple tree copy of D but that would make duplicate copies of the files.

[The following was moved from a comment.] Here's what I want to achieve. I have some music files in scattered locations. I'm able to create a single directory, D, that contains symlinks to all of them. My plan is to create the shadow directory D1 that initially contains copies of D's symlinks. As I play music I delete its nodes from D1, so that D1 only contains pointers to the music I haven't played (at various levels in D). Meanwhile my original music library is unmodified. I realize there might be other ways to achieve the same thing, but this method is concreptually simple and should require only standard shell programming.

Nmath avatar
ng flag
What is a "shadow directory"? Can you be more specific and less cryptic about what you intend to do? It's not clear what you mean by your notation "D"?
cn flag
"but that would make duplicate copies of the files." and "The idea is that operations on D1 should never modify D" are contradictions.
heynnema avatar
ru flag
This isn't a Ubuntu question... but rather a Windows question.
waltinator avatar
it flag
Seems like a silly idea - why wouldn't a version control system (`rcs`, `git`, `sccs`, ...) do the trick? However, if you're stuck on that idea, read `man inotify`.
us flag
Here's what I want to achieve . I have some music files in scattered locations. I'm able to create a single directory, D, that contains symlinks to all of them. My plan is to create the shadow directory D1 that initially contains copies of D's symlinks. As I play music I delete its nodes from D1, so that D1 only contains pointers to the music I haven't played (at various levels in D). Meanwhile my original music library is unmodified. I realize there might be other ways to achieve the same thing, but this method is concreptually simple and should require only standard shell programming.
vanadium avatar
cn flag
Rather than explaining in a comment, explain in your actual question - use edit. Comments may not be read or may disappear. What are "nodes" for you? How do you delete them? I only can delete files, folders or symlinks. I am afraid you are having an XY problem and that there are better ways to achieve what you want. A mirror copy of hard linked files, for example.
us flag
A version control system isn't really appropriate, because changes to the music library are purely additive. I hardly ever change something that's already there. I'm not expecting to add much more music to it.
us flag
Windows is not relevant here, since I'm doing everything under Linux, and for simplicity I want to do it all using the shell.
Score:1
cn flag

As well as by using ln, you can also make symbolic links to files with cp by using the -s flag. This is useful, because this still works with the -r and -a flags, meaning you can clone an entire tree of symlinks, from D to D1.

To work correctly, D must be an absolute path, or converted to one by using $(realpath D).

Putting this all together:

cp -asT "$(realpath D)" D1

To be clear, editing files in D1 will still change the originals in D, but links in D1 can be safely deleted.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.