Need BASH script help

Scott Bicknell scotbicknel at
Thu May 15 02:09:30 BST 2008

On Wednesday 14 May 2008 5:25:00 pm Joel Oliver wrote:
> Hello, I was wondering if there's anyone who can help me with
> my problem.
> OK.... I have a huge directory of movies (1200+) all in one
> directory and I wanted to "divide" them up...  Smarty me comes
> up with a great idea... symbolic links...  Now it would take
> forever to go into the terminal and ln -s every file so I
> discovered konqueror does this with a drag and drop... Great! 
> So dragging and dropping away I sorted all my movies
> alphebetically, by release date, by actors/actresses...  All
> was well except one BIG thing...
> I play them on my neuros OSD and mount them via NFS.  
> Konqueror really botched this as it created absolute path
> links and I needed relative it did this:
> my movies are in /big/sda/moviesa/
> my OSD mounts this in /mnt/media/nfs
> so the path after the mount is /mnt/media/nfs/sda/moviesa
> my sorted symbolic links are in
> /big/sda/Sorted/Alphebetical/A/movie.avi and these are linked
> like /big/sda/moviesa/movie.avi which is great on the computer
> but the path is wrong on the OSD.  I thought I could 'trick'
> the OSD with a symbolic link right in the root of the drive,
> but this area is solid state and won't let me write to it...
> So the big ?:
> Is there an easy recursive way to recurse through a whole
> directory structure, chop off the /big/sda and replace it with
> a relative ../../..
> If I link it as ../../../moviesa/movie.avi it works on both
> machines.... But that's alot of files to do one-by-one and I'm
> kinda stumped...
> Any quick ideas?  I realize this will work with every file as
> long as I keep all my links on the 3rd layer... otherwise I
> would need more or less "..'s"      :)
> Thanks in advance,
> Joel.

if you use a for loop in bash:

cd /big/sda/Sorted/Alphebetical/A
for movie in /big/sda/moviesa/*.avi; do
  ln ../../..${movie##*/} ${movie##*/}

then you should get the results you are looking for. 1200+ files 
may be too long for a bash for loop list, though. You may need 
to combine this with xargs to prevent any problems.

More information about the kubuntu-users mailing list