1

May somebody tell me if there is there some way to "merge" one dir into another?

I.e. let I have /some/directories/structure with subdirs/files. And now I want to "implantate" it into /etc for example. I.e. I need all subdirs/files from /some/directories/structure will be added into (should not replaced current contents of /etc) /etc or some other dir.

EDIT:

OK. Let's say I have a dir called prog. It contains a couple of a configuration files. This dir stored somewhere in my home dir while I develop my program and it must be installed into /etc in the working system. And now I want to debug my program, but to run it I need the prog dir (which stored in my home dir) became accessible in the /etc. So my question: may I do this in some "virtual" way (i.e. without copying, moving, rsyncing or even linking the prog into /etc)? Maybe there is something method to mount it, but (again) without physical creating anything in the /etc.

The key for me here is: "Do not forget something unneeded in the /etc".

Ohhh... I hope all is OK with my question now. :)

  • Why not go for mv? – Keyshov Borate Mar 4 '16 at 9:28
  • @Keys, I know about the mv, rsync etc, but I need to do this temporary and for reasons of developing so I don't want to worry in the future whether I removed my dirs/files, whether I updated them with a new version etc. – Serge Roussak Mar 4 '16 at 9:35
  • 2
    Can you edit your question and provide a structure in more detail that you want before and after, rather than just one directory name. Softlinks may do want you want, but it's not clear from your question (e.g. if you have /a/b/c and 'merge' it into /etc/ do you mean /etc/a/b/c or do you mean /etc/c). More detail please. – EightBitTony Mar 4 '16 at 9:48
  • mv /some/directories/structure/* /etc/ - you can use cp instead of mv for trial or better yet create a duplicate and try that code and see if that is what you want. I do not think it checks for duplicates though, if it finds any duplicate it may replace it. – Dean Mar 4 '16 at 9:56
  • I think you're asking for a solution to an intermediate problem. You have a problem of some kind, and you think the solution is to somehow make one directory look like it's somewhere else, but you can't work out how to do that. Rather than asking about that, you should ask about your root problem, the actual issue (maybe, I want my code to look in /etc/ for config files, but I don't have root access so i can't modify /etc/ which I guess is the issue here). – EightBitTony Mar 4 '16 at 13:16
1

I'm not either exactly getting what you're trying to, to be honest it makes no sense to me at all.. But when you're talking about virtual and mounts - I suspect you're thinking somewhere in the direction of a bind mount?!

What is a bind mount?

Linux bind mount

Under Linux, bind mounts are available as a kernel feature. You can create one with the mount command, by passing either the --bind command line option or the bind mount option. The following two commands are equivalent:

# mount --bind /some/where /else/where

# mount -o bind /some/where /else/where

Here, the “device” /some/where is not a disk partition like in the case of an on-disk filesystem, but an existing directory. The mount point /else/where must be an existing directory as usual.

Note that no filesystem type is specified either way: making a bind mount doesn't involve a filesystem driver, it copies the kernel data structures from the original mount.

  • I suspect this might be a solution, but rather than link to the post, can you describe the commands Serge could use to solve his issue? Also, I don't think the commentary after it is necessary, if you think you have a technical solution (and I think you do), then keep the answer technical and helpful, so that it can help the OP and anyone else who finds this question. – EightBitTony Mar 4 '16 at 11:46
  • 1
    I agree. I've edited my answer accordingly. – oanoss Mar 4 '16 at 12:21
  • At first I thought this might work, but in hindsight and with some testing, you need a mount point in /etc/ to bind mount over. So you can only do mount --bind /my/dir /etc/dir if /etc/dir already exists (and you need to be root to create /etc/dir and probably to do the subsequent mount --bind. – EightBitTony Mar 4 '16 at 13:24
1

I would switch this around. You need the code you are developing to access some configuration files in a directory it believes is /etc/ (and may be a sub-directory within that, although you are not clear).

Rather than try and find a way to fake that at the filesystem level, do what many other applications do and provide a customisable configuration directory.

Tell your application that the config files are present in /home/user/prog/etc/ or /usr/local/etc/ and debug it that way. Hard-coding config directories are bad for a number of reasons.

Once you can change where your code looks for config, you can test as much as you want without any access to /etc/ which I'm guessing is the root issue you have.

  • I think you are right. I think I will do you had suggested here, but unfortunately, I had not developed this soft from scratch. So there is which there is... – Serge Roussak Mar 4 '16 at 13:19
0

Don't know how big is you data, but you can do rsync for moving your data from source to destination. below command will not delete anything from your destination.

rsync -avz /some/directories/structure/ /etc/

Below command will make changed in your destination dir.

rsync -av --delete /some/directories/structure/ /etc/

This will delete the file from /etc/ which is not present in /some/directories/structure/

  • you have a look at this link – Mongrel Mar 4 '16 at 10:10
  • I know about rsync, but I don't want to use it here. – Serge Roussak Mar 4 '16 at 10:26
  • Then what you need exactly. edit your question. – Mongrel Mar 4 '16 at 10:35
0

Your intent is unclear to me, but perhaps what you need is a symbolic link in /etc. If so, consult man ln.

  • But he doesn't want to replace the current content of /etc. – Mongrel Mar 4 '16 at 11:07

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.