FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Kubuntu User

 
 
LinkBack Thread Tools
 
Old 05-15-2008, 12:25 AM
Joel Oliver
 
Default Need BASH script help

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
paths....like 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.


--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 01:09 AM
Scott Bicknell
 
Default Need BASH script help

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 paths....like 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##*/}
done

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.
--
Scott

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 01:12 AM
Scott Bicknell
 
Default Need BASH script help

On Wednesday 14 May 2008 6:09:30 pm Scott Bicknell wrote:
> 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 paths....like 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##*/}
> done
>
> 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.
> --
> Scott

should have put a slash between the ..'s and the $movie variable.
ln ../../../${movie##*/} ${movie##*/}
--
Scott

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 01:13 AM
Scott Bicknell
 
Default Need BASH script help

On Wednesday 14 May 2008 6:12:12 pm Scott Bicknell wrote:
> On Wednesday 14 May 2008 6:09:30 pm Scott Bicknell wrote:
> > 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 paths....like 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##*/}
> > done
> >
> > 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.
> > --
> > Scott
>
> should have put a slash between the ..'s and the $movie
> variable. ln ../../../${movie##*/} ${movie##*/}
> --
> Scott

And -s in the ln command-line
ln -s ../../../${movie##*/} ${movie##*/}
--
Scott

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 01:26 AM
"Jared Greenwald"
 
Default Need BASH script help

Something like this? I always remember the ln format by using real
and fake hence the var names.

cd /big/sda
find Sorted -type l -name "*avi" | while read fake ; do
real="../../../moviesa/"${fake##*/}
ln -svf $real $fake
done

I make no guarantee that it will work, just a suggestion. You should
probably replace the ln line with 'echo "$real::$fake"' and run that
once to make sure that its going to be doing what you want.

On Wed, May 14, 2008 at 8:25 PM, Joel Oliver <joelol75@verizon.net> 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
> paths....like 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.
>
>
> --
> kubuntu-users mailing list
> kubuntu-users@lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
>

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 12:32 PM
Joel Oliver
 
Default Need BASH script help

Jared Greenwald wrote:
> Something like this? I always remember the ln format by using real
> and fake hence the var names.
>
> cd /big/sda
> find Sorted -type l -name "*avi" | while read fake ; do
> real="../../../moviesa/"${fake##*/}
> ln -svf $real $fake
> done
>
> I make no guarantee that it will work, just a suggestion. You should
> probably replace the ln line with 'echo "$real::$fake"' and run that
> once to make sure that its going to be doing what you want.
>
> On Wed, May 14, 2008 at 8:25 PM, Joel Oliver <joelol75@verizon.net> wrote:
>
Thanks! Got it to work finally... The big problem I had was with
spaces... It was chopping off anything before the space so the link
failed.... BTW here's what worked a charm:


#!/bin/bash
cd /big/sda1
find Sorted -type l -name "*avi" | while read fake ; do
real="../../../moviesa/"${fake##*/}""
ln -svf "$real" "$fake"
done



Thanks a million!

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 12:33 PM
"Brad De Vries"
 
Default Need BASH script help

On Wed, May 14, 2008 at 8:25 PM, Joel Oliver <joelol75@verizon.net> 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
> paths....like 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.

Actually, why do you have to use symbolic links? If you use a hard
link then the file's data is accessible directly from the filename --
no link traversal required.

Just a thought, albeit a good one. :-)

Brad.

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 01:27 PM
Joel Oliver
 
Default Need BASH script help

Brad De Vries wrote:
> On Wed, May 14, 2008 at 8:25 PM, Joel Oliver <joelol75@verizon.net> 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
>> paths....like 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.
>>
>
> Actually, why do you have to use symbolic links? If you use a hard
> link then the file's data is accessible directly from the filename --
> no link traversal required.
>
> Just a thought, albeit a good one. :-)
>
> Brad.
>
>
I thought it was a big no-no to use hard links.... Kinda like
telnetting in as root, storing compressed reiserfs .img files on a
reiser partition, using special characters [/<> in fileneames... I know
all the above can be done but shouldn't for some reason or another... I
think I heard something about hard links are bad but ... I don't know why



--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 03:33 PM
Scott Bicknell
 
Default Need BASH script help

On Thursday 15 May 2008 6:27:08 am Joel Oliver wrote:
> > Actually, why do you have to use symbolic links? *If you use
> > a hard link then the file's data is accessible directly from
> > the filename -- no link traversal required.
> >
> > Just a thought, albeit a good one. *:-)
> >
> > Brad.
> >
> > *
>
> I thought it was a big no-no to use hard links.... * Kinda
> like telnetting in as root, storing compressed reiserfs .img
> files on a reiser partition, using special characters [/<> in
> fileneames... I know all the above can be done but shouldn't
> for some reason or another... *I think I heard something about
> hard links are bad but ... I don't know why

Hard links are just a little more limited. You cannot use them if
they point across file systems or if they point to a directory.
They can be somewhat easier to overlook in file listings, also,
but they are not bad. Otherwise, they would be more of a bug
than a feature.
--
Scott

--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 
Old 05-15-2008, 03:41 PM
Joel Oliver
 
Default Need BASH script help

Scott Bicknell wrote:
> On Thursday 15 May 2008 6:27:08 am Joel Oliver wrote:
>
>>> Actually, why do you have to use symbolic links? If you use
>>> a hard link then the file's data is accessible directly from
>>> the filename -- no link traversal required.
>>>
>>> Just a thought, albeit a good one. :-)
>>>
>>> Brad.
>>>
>>>
>>>
>> I thought it was a big no-no to use hard links.... Kinda
>> like telnetting in as root, storing compressed reiserfs .img
>> files on a reiser partition, using special characters [/<> in
>> fileneames... I know all the above can be done but shouldn't
>> for some reason or another... I think I heard something about
>> hard links are bad but ... I don't know why
>>
>
> Hard links are just a little more limited. You cannot use them if
> they point across file systems or if they point to a directory.
> They can be somewhat easier to overlook in file listings, also,
> but they are not bad. Otherwise, they would be more of a bug
> than a feature.
>
OK, I just read up on soft vs hard links and now I feel like a doof....
Hard links would be the way to go.... doh! And I never have to worry
about breaking them.... They would be ideal for what I wanted to do...
Ohh well, another learning experience

Thanks for the help...



--
kubuntu-users mailing list
kubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
 

Thread Tools




All times are GMT. The time now is 01:04 PM.

VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org