PDA

View Full Version : directory with results of shell script



simonloach
30th October 2007, 11:26 PM
Is it possible in Linux to have a directory that contains a list of files (or even directories) that are returned by a shell script? So for example I have a directory /home/simon/music-mp3 which when I use ls on returns a list of all of my mp3 music and also have it so i can play one of the files in /home/simon/music-mp3 as if they were actually in that directory. Also this directory would need to be automatically refreshed each time it is accessed to reflect any updates.

This would be very useful for me. Thanks in advance for any help!

Dies
30th October 2007, 11:35 PM
I'm probably just not understanding what you need to do but it sure sounds like you just want a symbolic link?

ln -s <insert some directory here> /home/simon/music-mp3

simonloach
30th October 2007, 11:40 PM
not really, I want to make files in /home/simon/music-mp3 as symbolic links to all the mp3 files returned by a shell script.

scottro
31st October 2007, 12:57 AM
for i in <whatever your script does to to return the mp3 file names>
do
ln -s "$i" /home/simon/mp3/
done

I just tried it with

touch 1 2 3 4
for i in 1 2 3 4;do
ln -s $i /home/scottro/test/
done

You might want to try it with
echo ln -s $i

first to make sure it doesn't hurt anythng.

ljos
31st October 2007, 01:00 AM
OK you don't want to link the dir but all the files instead. Maybe this would work:

cd /home/simon/music-mp3
find . -exec ln -s `pwd`/{} <insert path to dir here>/{} \;

The <path to dir> can be relative from /home/simon/music-mp3 or full path.

stevea
31st October 2007, 02:06 AM
Yeah - but wtf ? Why do you want symbolic links at all ? Can't you just play the media from where it lies ?

PLEASE explain what you are trying to accomplish (give a real example). Your problem is as clear as mud.
Why don't you just drop a link to the directory onto your desktop and then you can just open the folder, and click on a file to play it. Or you might want to use something like rythmbox that has it's own multi-dimensional indexing system.

strongly suspect you're not thinking about the problem correctly.

simonloach
31st October 2007, 12:15 PM
Thanks a lot ljos works just how I wanted it to. As for why anyone would want to do it, why not? I'm sure there are better ways but symbolic links are just so cool!