Creating links to multiple folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating links to multiple folders
# 1  
Old 04-14-2009
Creating links to multiple folders

Hi All,

First of all, I'm a unix newbie so don't be to hard on me Smilie 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 Smilie ) 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.
# 2  
Old 04-14-2009
Cron, daemon, either way

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.
# 3  
Old 04-14-2009
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 Smilie but I'm sure with some googling, trial and error, I will succeed.

Thanks for pointing me in the right direction!

Regards,

Kees.
# 4  
Old 04-14-2009
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...
Code:
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.
# 5  
Old 04-15-2009
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 :-)

1) create a dummy directory to act as the catalogue and cd do it
2) the next commnd should do it:
Code:
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 :-)

pen
# 6  
Old 04-15-2009
Quote:
Originally Posted by d.the.duck
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;
}
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.
# 7  
Old 04-15-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Creating a sub-folder in multiple folders

Hi I've been trying to find an answer to this question and was hoping someone would be able to help me. I want to add a sub-folder to to an existing structure: for example /toys/toy_1/new /toys/toy_2/new /toys/toy_3/new There are humdreds of theses folders - what i want to do is add a... (2 Replies)
Discussion started by: LouSan
2 Replies

2. Shell Programming and Scripting

awk creating folders

Hello, im trying to create folders from text file and i get errors :( #!/bin/bash awk 'BEGIN { RS = "/" } ; { mkdir $1, mkdir $2, mkdir $3, mkdir $4, mkdir $5}' zodziai.txt im new in linux stuff just trying to learn. The idea is i want to create new folders from words in text file. I... (4 Replies)
Discussion started by: boxstep
4 Replies

3. Shell Programming and Scripting

Script for creating symbolic links to my photos (*.JPG)

Hi, I have all my pictures as *.JPG and *.CR2 in the following folder structure: /media/a_2TB/pictures/year/year-month-day-hour/picture*.* But sometimes I added a subdirectory --> /media/a_2TB/pictures/year/year-month-day-hour/suba/picture*.*... (3 Replies)
Discussion started by: 8200
3 Replies

4. Shell Programming and Scripting

Creating matrix from folders and subfolders

Hello, Greetings! please help me produce the following solution. I need to produce one big matrix file from several files in different levels. If it helps, the index folder provides information on chromosome index and the data folder provides information on values for chromosomes. there... (8 Replies)
Discussion started by: newbie83
8 Replies

5. IP Networking

Accessingand creating folders in Machines using IP

Hi all, I am working on a project where I need to access four random machines from a given subnet mask and sending files across the machines similar to peer to peer file systems. Now my question is. Given a subnet mask or If I obtain a random IP address of a machine from Subnet mask, how can I... (4 Replies)
Discussion started by: Pavan Kumar
4 Replies

6. Programming

creating soft links

i'm trying to write a c code to copy a soft link over to a specified directory. Is it possible to do this without using symlink()? if so, what can I use? Thanks! (2 Replies)
Discussion started by: l flipboi l
2 Replies

7. Shell Programming and Scripting

Creating tar excluding links

hi, How do i create a tar file of a directory excluding the links in that particular directory and its sub-directories. The below command doesnt work for me. tar -cvf abc.tar /dir1 --exclude"^l" (1 Reply)
Discussion started by: yesmani
1 Replies

8. Solaris

Will creating symbolic links affect users

Hi, I have a quick question with regards to creating symbolic links. Would creating a symbolic link from one directory to a file in another cause any issues for users that are currently logged into the box. I don't believe it will unless they are using the file in question, but I would like... (2 Replies)
Discussion started by: Chains
2 Replies

9. Shell Programming and Scripting

creating multiple links with ln

I want to make a symbolic link to a set of files in a particular directory if they exist. The number of files in the set is not known. The following script fails because it is ambigious. if(-f dir1/*.a) then ln -s dir1/*.a dir2/ endif Can anyone help me? Thanks a lot. (1 Reply)
Discussion started by: Deanne
1 Replies

10. Shell Programming and Scripting

list folders but not symbolic links

Hii... I want to list folders (no files and no symbolic links).. But my is giving me error.. please help... Esham (7 Replies)
Discussion started by: esham
7 Replies
Login or Register to Ask a Question