Find the answer to your Linux question:
Results 1 to 5 of 5
I was wondering if it was possible to create a sort of "virtual directory" that lists contents of other directories in a single directory. If that sounded confusing, here's an ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    dyn
    dyn is offline
    Just Joined!
    Join Date
    Oct 2007
    Posts
    4

    Question virtual directories?


    I was wondering if it was possible to create a sort of "virtual directory" that lists contents of other directories in a single directory. If that sounded confusing, here's an example:

    dir1
    file1
    file2
    dir2
    file3
    file4

    You then create a "virtual directory" called dir3. If you type ls dir3 at a console, you see:
    file1
    file2
    file3
    file4

    Obviously one solution would be to make links to dir1 and dir2 within dir3; but an ls dir3 would then produce:
    dir1
    dir2

    This allows me to get to them more quickly perhaps. Also, from here I could do an ls * or even an ls -R *.

    While this is a viable solution, I just wondered if there was something out there that could accomplish this better. If not, I'm sure a perl or python script could get this done, although perhaps not worth the time.

    Any ideas?

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,429
    I think you want Symbolic Links.
    ln -s /home/dir1 /home/dir3
    Check that out. Else I miss understoud you.
    New Users, please read this..
    Google first, then ask..

  3. #3
    dyn
    dyn is offline
    Just Joined!
    Join Date
    Oct 2007
    Posts
    4
    Symbolic links are good for linking one directory to another. But, what I was asking was if it was possible to link two or more directories to one directory.

    I want the contents of two directories to be the output when I list the contents of one directory.

    I thought the example made this clear, but perhaps it didn't. Seeing as you're the only one who replied, I'll assume it's not possible to do this in any traditional way.

    Thanks for the response, though.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Nov 2004
    Location
    home
    Posts
    796
    You may be able to use lndir for this, it will create a directory tree of symlinks to another directory tree, it might work for 2 directoried. Or you could use a simple bash loop:

    Code:
    for file in ../some/dir ; do ln -s $file ; done
    Something similar to that ran for 2 different directories should work.

  6. #5
    dyn
    dyn is offline
    Just Joined!
    Join Date
    Oct 2007
    Posts
    4
    Thanks valan!

    That's exactly what I wanted to do. lndir seems to accomplish this for the most part. I also tried the bash script, which has similar results. I had to tweak it a bit:
    Code:
    for file in ../some/dir/* ; do ln -s "$file" ; done
    lndir should really be listed under See Also in the man page for ln.

    Thanks again for the useful tips.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •