Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've got a source control system at work that I can't modify which scatters a bunch of files in unfortunate places. My IDE expects these folders to be in a single unified location. Normally I'd just symlink the shit out of everything, but to make things worse, some of the folders must be recursively merged. I have a guarantee that there are no overlapping filenames, but we're talking about thousands of files, more than I'll do by hand.

I've looked into unionfs and aufs, but it's a corporate machine, so no mucking about with the kernel (not to mention the "getting started" docs for these wang chung).

Is there another way to do this?

share|improve this question
    
Does your kernel have fuse enabled? It is enabled by default under Ubuntu. The point of FUSE is that everything happens in userland, there's no need to muck about with the kernel. Try unionfs-fuse (compile it from source if it isn't included in your release of Ubuntu). –  Gilles Jun 12 '12 at 22:46
add comment

1 Answer

I don't know the tools you are using exactly and how they behave with symbolic links, but you can "copy" whole tree using symlinks (or hard links if you want) automatically using -s option of cp (or -l for hard links).


Let's have a look at below example.

.
├── 1
│   ├── s -> x
│   ├── x
│   ├── y
│   └── z
│       └── 1
└── 2
    ├── a
    │   └── 2
    ├── b
    └── c

If you want co symlink 1/ files to 2/ in current directory, then you can just simply do:

cp -ans "$PWD/1/"* 2/

Now 2/ looks like:

.
...
└── 2
    ├── a
    │   └── 2
    ├── b
    ├── c
    ├── s -> /home/przemoc/links/1/s
    ├── x -> /home/przemoc/links/1/x
    ├── y -> /home/przemoc/links/1/y
    └── z
        └── 1 -> /home/przemoc/links/1/z/1

Explanation of used cp options:

  • -a or --archive
    preserves attributes, links and copies directories recursively (it's in fact alias of -dR --preserve=all)
  • -n or --no-clobber
    prevents overwriting existing files
  • -s or --symbolic-link
    makes symbolic links instead of literal copying

Source file paths have to be absolute in such case (that's why I used $PWD), because cp "can make relative symbolic links only in current directory".

Hope it helps a bit.

share|improve this answer
    
cp -s is new to me, so thank you for that, but this seems to be a one-time operation. I'll need to do this repeatedly, every time I sync with the codebase or add a file. This also doesn't cover cases where the folders need to be merged. For example, if I had ./1/a/3, in my resulting folder I'd want to see ./2/a/[2,3], but I'm pretty sure this copy operation would clobber files. Does that make sense? –  Hounshell Jun 12 '12 at 21:58
1  
@Hounshell: You can do it repeatedly, but it won't work with future renames and such, it's simply a copy, only using symlinks. You can possibly go with hard links as long as "unfortunate places" are on the same filesystem. Your description is quite enigmatic, but to preserve some control I would make this unified location consisting only of links (symbolic or hard, whatever suits you better), so it could be easily cleaned and recreated with simple script using cp -ans from different places to your one "merged" directory. As for your question of folder merging, it will work fine, don't worry. –  przemoc Jun 12 '12 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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