How can I create a filesystem "view" of a folder that excludes certain files?

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.


I found this:

Cmdfs is a FUSE virtual filesystem which applies an arbitary filter command to selected files in a source directory tree to create the destination files.

Here is an article about it: http://www.linux-magazine.com/Online/Features/Cmdfs

And the source on github: https://github.com/mikeswain/cmdfs


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.