sh Scripting - String Manipulation
Drew Tomlinson
drew at mykitchentable.net
Fri Oct 14 08:41:16 PDT 2005
On 10/13/2005 9:03 PM Paul Schmehl wrote:
> --On October 13, 2005 4:04:45 PM -0700 Drew Tomlinson
> <drew at mykitchentable.net> wrote:
>
>> I'm working on a script that reads a directory using 'find' and its
>> '-exec' primary to create a symlink to the file. So for example, I have
>> the following command:
>>
> find /multimedia/Pictures -iname "*.jpg" -print | cut -d'/' -f4
>
> You'll have to play with the field value (-f) to get the right
> location, but this would return only the filename.
Thanks for your reply. I will look at 'cut'. Didn't know about that
one. :)
>> This command returns a bunch of filenames. Here's an example of one:
>>
>> /multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG
>>
>> What I'd like to is get '-exec' to run this command:
>>
> I don't understand what you're trying to do here.
>
>> ln -s "/multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG" "2005
>> Kimberly & Rich/IMG_1210.JPG"
>>
> Are you trying to create symlinks in a different directory? If so,
> why not do this?
Yes.
> ln -s dir1/ dir2/
>
> Then, when you add new files to dir1/ they will automatically show up
> in dir2/ because the dir is symlinked rather than the individual files.
That's a good idea (and something else I never thought of) if I wanted
all the files, not just the *.jpg files. And as I'll explain below, I
intend to expand this script to work with additional directories where I
might just want the *.mp3 or the just the *.avi, *.mpg, etc. My thought
was to build a script and run it through cron to keep the symlinks updated.
> What exactly are you trying to accomplish?
I have a FBSD 5.4 box running Samba. One of the shares on that box
contains all of my pictures, video clips, and music. I have built a
MythTV box on Gentoo. My first thought was to just mount the smbfs
share on the Gentoo box so that MythTV could access my media files. But
then I found out that MythTV needs write access to the share so it can
cache thumbnails and video information. I don't want MythTV writing to
my FBSD box because then it messes up other stuff that uses the same
share. Thus my idea was to mount the share read-only and create
symlinks to the files in a local directory on the Gentoo box. Then
MythTV could write its files locally and leave the FBSD box unaltered.
So specifically, I have the FBSD share mounted on the Gentoo box as
/multimedia. Within the FBSD share are subdirs named Pictures, Video,
and Music. Underneath these folders are many sub folders that contain
the actual files. I want to make symlinks on the Gentoo box in
/tv/multimedia for each of these directories but lose the subdir
structure. I need to loose the subdir structure as MythTV doesn't
recurse directories in some instances (specifically the MythGallery plugin).
So in the above example, the Gentoo box sees "/multimedia/Pictures/2005
Kimberly & Rich/IMG_1210.JPG" as the original file mounted read-only. I
want a symlink named "/tv/multimedia/2005_Kimberly_&_Rich-IMG_1210.JPG"
to point to "/multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG".
But please note that some files are more nested than the above example.
Hopefully, this makes sense? But being new to scripting and knowing
enough about *nix to realize there's lots of ways to accomplish any one
task, I'm looking for guidance and suggestions as to the "most generally
accepted" way to go about this one. :)
Thanks for your time,
Drew
--
Visit The Alchemist's Warehouse
Magic Tricks, DVDs, Videos, Books, & More!
http://www.alchemistswarehouse.com
More information about the freebsd-questions
mailing list