Creating links to multiple folders

Hi All,

First of all, I'm a unix newbie so don't be to hard on me :slight_smile: I'm not even sure if the thing that I want is even possible but here goes nothing:

On my linux based NAS I have the following structure:

videos
|---movie 1
|---movie 2
|---movie 3
|
USBDISK
|---videos
|--- movie 4
|--- movie 5

No I would really like, when I list "/videos" to show everything thats in the "/videos" folder PLUS everything that's in the "/USBDISK/videos" folder. No I'm kind of hoping that can be arranged with one soft link creation, but I don't think that's really possible. Another option would be to create a cronjob (I googled that term :slight_smile: ) which looks at "/USBDISK/videos" every hour or so and will create a symbolic link for each and every movie that's not linked to "/videos" at that point. But I don't know if that's possible either... and if it is I have NO clue how to.

I hope my question is a little clear and that someone can help me... if not... thanks for reading that kind of noob question!

Regards,

Kees.

You could just create a small perl program that would do that for you. something like

#!/usr/bin/perl
use strict;
use warnings;

my $target = "/usb/videos";
my $prefix = "/videos";
my $cmd = "ln -F";

while (1){
my @foo= `ls -1 /videos`
foreach my $bar(@foo){
chomp $bar;
my $order = $cmd . " ".$target.$bar." ".$prefix.$bar
system ($order);
}
sleep 1200;
}

Bear in mind, you'd need to specifiy your own perl, clean up paths to use the full path names (you don't have to use absolute paths, but I always do). And this is the daemon verison, updates every 1200 seconds. No eror checking or interrupt handling. Not great work, but hacked to make the point.

Hi d the duck,

First of thanks for your quick reply! I'm glad to hear that it is possible what I want.

Secondly, I will have the huge task of trying to understand what and how you do what you do, because it's kind of out of my league for now :slight_smile: but I'm sure with some googling, trial and error, I will succeed.

Thanks for pointing me in the right direction!

Regards,

Kees.

There are 2 types of link that you can create...hard links and soft, or symbolic links. Both are created using the ln command.
Hard links are created by the system creating an extra reference to a specific disk inode, so you have 2 or more filenames pointing at the same piece of disk. Once created, you can't tell which was the original file and which is the link. A file won't actually be deleted until all links to it are removed. When you run the "ls -l" command, the second column (normally 1s and 2s) is the number of links to the file. As hard links are created at disk level, you clearly can't have hard links crossing file systems.
A soft link is simply another file that contains an arbitrary string which would be the path to another file anywhere on the system. Note that it could also be an incorrect path to a non-existent file! Consider it similar to a Windoze desktop shortcut.
So back to your example, in your videos directory, you can run the command...

ln -s /usb/videos/movie4

By default, the symbolic name will match the name of the target file so a target link name isn't necessary here. This will create a symbolic link to movie4 and allow you to access it directly in the videos directory as if it was really there. Obviously if you had a real movie5 in videos as well as another movie5 in /usb/videos, you'll have to give the link another name.
"rm movie4" in the videos directory will remove the link and NOT the target file, while the same command in the /usb/videos directory will remove the file and would leave the /videos/movie4 link pointing at a non-existent file.

d.the.duck has suggested using 'ln-F' ... this is for directory linking rather than files and I'm not sure will work as expected.

Hope that helps.

Hi!

JerryHone gave you an excellent background pack of information; here's a practical (but perhaps clumsy, a sort of quick-and-dirty-and-don't-tell-your-mama) example.
One clumsy but an efficient way is to use softlinks (file or directory names pointint to the ACTUAL file or directory). This is now the best way for everyday use, but enough for one-time usage, or when your collection doesn't change a lot due time. Or when you don't want to start creating your own movie database :slight_smile:

1) create a dummy directory to act as the catalogue and cd do it
2) the next commnd should do it:

find paths_to_your_videos -type f -exec ln -s \{\} . \;

for example, find /videos /

Note the spaces around the dot \;
That should produce a nice set of soft links mentioned here earlier, pointing the here and there and wherevere your files actually are. If you need, you can keep this updated by running the find command (see above) from at or cron.

Uh, and for newbies I would recomment a very funny but still rather good guidebook titled "Unix for Dummies". It's a handy book, and once you have learder it from cover to cover you can either burn it, or laugh at its humor :slight_smile:

pen

if using shell functions (ls, ln), might as well use a shell script. In Perl, the equivalent to hard link is link(). see perldoc -f link. For soft link, its symlink(). See perldoc -f symlink.

I am not sure if you really looking fir it or not

Why don't u create a alias
alias lvideo='ls /videos ; ls /USBDISK/videos'

or simply run in shell

ls -l /videos ; ls -l /USBDISK/videos

Probably because the device is a NAS and thus a command-line listing isn't always possible/desired?

I am still somewhat of a n00b myself, so forgive the poor Perl. And I tend to default to perl, and rarely use shell scripts.