Is there a method of creating a symbolic file that refers to the contents of a directory?

So for example, calling:

cat all_keys

would give the same output as:

cat keys/key1+keys/key2+etc...

I've tried creating a symbolic link to the directory, tried various flags to try and get the Data and even trying to make a symbolic link that runs the command:

cat keys/*

Akin to the manner in which Logical Volume can span multiple physical partitions, I'd like to know if I can create a file that spans an arbitrary and flexible length of data.

For context: I'm getting really frustrated with the flatfile system used for ssh authorised_keys.

I know I could use a SED to remove the key data but that seems messy. I'm sure there's other uses outside of this scope too.

Thanks in Advance.


In the end I just went with SED in place to make the deletions and comments before the key block to identify it.

It's a little more expensive CPU wise than I'd have liked, but avoids either repeating all the key data in a folder and a file or trying to make a fuse directory.

  • while I never use it myslef, this sound like fuse filesystem. – Archemar Oct 16 '15 at 12:14
  • Possibly, or a new type of symbolic link. I fear that writing a new FS or link type may well be beyond my ability - but if all else fails, I'll give it a try. – Minothor Oct 16 '15 at 12:53
  • This is a user level FS. – Archemar Oct 16 '15 at 12:54
  • Cheers, Archemar, I'm looking into it just in case, I'll be honest though, this is deeper into C++ than I'm currently familiar or comfortable with, so if push comes to shove, I'll fall back on a SED script for this use-case. – Minothor Oct 16 '15 at 13:12

The only way to do this that I know of would be to write a new filesystem, probably at the user-level using FUSE or similar. This isn't intractable (I've done it in ~200 lines of Python), but it's a fair bit of fiddly detail work, and it may not be the best fit for this application (in particular, you would need to mount the new FS on .ssh, meaning you also have to emulate a real filesystem or pass requests through to handle the other flat files which need to be in there).

Another option might be to write a script which generates the flat file from a source directory (which might be as simple as cat dir/* >file), then run it on a cronjob or triggered by inotify or similar. A simple script might be:

while inotifywait ~/ssh_source_dir; do
    cat ~/ssh_source_dir/* >~/.ssh/authorized_keys

(Which assuredly needs tuning for precise behavior and reliability, but it's a prototype.)

  • Thanks for the suggestion, in the end though I just went with a combo of SED editing in place and using comments to identify the keys, messy but it avoids having duplicate data. – Minothor Oct 28 '15 at 13:31
  • (sorry for the belated acceptance, this was the only viable and efficient solution in the end) – Minothor Jan 25 '16 at 15:07

You can use split to chop a large file like your allkeys file into pieces.

read man split for the options.

  • Thanks for the suggestion, but I fear that it wouldn't fare well with key data, some users use 1024bits, others use 2048bits. Ideally, what I'm hoping to do is the inverse of that, a file that when read, joins multiple files into one on the fly, avoiding the need for pattern matching, digging and triage. Split will definitely help with other things I write though, thanks! – Minothor Oct 16 '15 at 12:47

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.