Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to have a path in the filesystem that shows the entire contents of some other path, excluding a few certain files of my choosing. For example, if the following already exists,

original-path
├── file1
├── file2
├── file3
├── file4
├── folder1
│   ├── file1
│   └── file2
└── folder2
    ├── file1
    └── file2

I want to be able to exclude /file1, /folder1/file1, and /folder2 from a new path that otherwise points to the same data:

new-path
├── file2
├── file3
├── file4
└── folder1
    └── file2

How can I accomplish this? Some kind of bind mount, FUSE filesystem, or clever linking scheme?

share|improve this question
add comment

2 Answers

I think you're on the right page already. You've mentioned the two things I would have suggested.

FUSE is apparently pretty simple to get stuck into. I've had a similar question to this a while back and one of the answers mentioned FUSE. I found a simpler option (which I'll explain in a second) but if that isn't desirable, FUSE might be worth investigating.

My problem was I have an incoming directory where clients dump all sorts of crap. I needed a way to be allowed to sort them into deep directories (eg /work/client-name/project/document.ext) but still have a top-level grasp to see what was new. I wrote a little bash script that maintained a "recent" directory that contained symlinks to the recent content.

Something as simple as this might work for you. Just keep chaining on -not -name arguments, or filter positively if you have something you can look for...

#!/bin/bash

rm new-path/* # clean up old symlinks
find original-path -type d -maxdepth 1 -not -name folder2\
    -exec ln -s -t new-path/ {} +

This is only first level but you could expand it to:

  • Search for the directories you wanted to mirror
  • Create new (real) directories in new-path
  • Loop the new directories and search the old versions for files you want, creating symlinks. Like the original find with some augmentation to the paths.
  • The initial clean-up statement will also need to be rm -rf new-path/* because they're real dirs. Be careful with it.
share|improve this answer
add comment
up vote 2 down vote accepted

rofs-filtered, a FUSE filesystem derived from Read-Only Filesystem, can exclude files using regular expressions:

$ cat rofs-filtered.rc 
^/file1$
^/folder1/file1$
^/folder2$
$ rofs-filtered -c /home/ak/sandbox/rofs-filtered.rc /home/ak/sandbox/original-path /home/ak/sandbox/new-path
$ tree {original,new}-path
original-path
├── file1
├── file2
├── file3
├── file4
├── folder1
│   ├── file1
│   └── file2
└── folder2
    ├── file1
    └── file2
new-path
├── file2
├── file3
├── file4
└── folder1
    └── file2

rofs-filtered isn't available in Ubuntu's repositories, but I've started a request to have it added.

share|improve this answer
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.