3

I have a folder with lots of files. Some of them are more often used and required than others.

I want to have "folders" which represent a view to that directory with a certain filter. Filters like file name "has _final" or file size < 5 mb or something like that.

I know, there are commands like find, grep and so on. I want their result as a file system directory with "hard links" .

Is there any way to do this?

4

A short search in Google produce several FUSE solutions:

2
  • what were your google search words? (because mine were obviously wrong :) – wuppi Sep 3 '17 at 10:31
  • I think the hard part is to figure out FUSE is the key, once that has been figured out, then just search "FUSE for directory filtering" which come out with various solutions. – S P Arif Sahari Wibowo Sep 17 '17 at 22:26
0

You say you want hard links — but you also say that you want '"folders" which represent a view'.  If you're happy with something that looks like what you want, consider shell functions:

ls_final() { ls "$@" | grep has_final; }

You question currently says

file name "has _final"

I don't know whether that's a typo for

file name has "_final"

If it is, change the grep accordingly.

Filtering for file size is a bit harder, especially if the selection limit is not a power of ten (or a small integer times a power of ten).  It can be managed with grep, if you always use the -l (lower-case L) option, or equivalent.  There are probably other approaches, although it might be very hard to do this elegantly, securely, and efficiently.

TL;DR If you form the habit of using ls_final, ls_small, etc., it will look like only the desired files are present.

1
  • "has _final" meant to be the file name has the string "_final" in it the purpose is, to supply that "folder" to another program, which works on it. So a "real folder" is the desired thing – wuppi Sep 19 '17 at 7:42
-1
cd /path/to/filter_directory
find /source/dir -mindepth 1 -maxdepth 1 [...filter tests...] -exec ln -t . {} +
3
  • ok this creates links automatically once. this is not a kind of "live view" (I like to compare it to sql and views ...) – wuppi Sep 2 '17 at 18:51
  • 1
    @wuppi That is impossible with simple tools if you want a real-time view. You would have to write your own user space filesystem for FUSE. That does not have to be difficult (especially if you can limit it to displaying symlinks to the real target) but it is software development. – Hauke Laging Sep 2 '17 at 19:01
  • Yes, the other answer adresses these options. Thanks for your approach, which is a quiete effective one for non "live" requirements. As I did not mention the "live" aspect in my question, this answer is still a valid one and I do not understand the -1 – wuppi Sep 3 '17 at 10:26

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.