Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 15th November 2009, 04:14 AM
SendDerek's Avatar
SendDerek Offline
Registered User
 
Join Date: Nov 2007
Posts: 198
windows_xp_2003safari
Question Automatically Create Destination Directory Structure for Softlinks (ln -s)?

Hello All!

I have a file that has been created by exiftools and then parsed and cut to fit my needs and thrown into a file that looks like this:

Code:
ln -s /source/directory/2009/10/img1.jpg /destination/directory/gallery/2009/10/img1.jpg
ln -s /source/directory/2009/10/img2.jpg /destination/directory/gallery/2009/10/img2.jpg
ln -s /source/directory/2009/10/img3.jpg /destination/directory/gallery/2009/10/img3.jpg
ln -s /source/directory/2009/10/img4.jpg /destination/directory/gallery/2009/10/img4.jpg
ln -s /source/directory/2009/11/img1.jpg /destination/directory/gallery/2009/11/img1.jpg
ln -s /source/directory/2009/11/img2.jpg /destination/directory/gallery/2009/11/img2.jpg
ln -s /source/directory/2009/11/img3.jpg /destination/directory/gallery/2009/11/img3.jpg
ln -s /source/directory/2009/11/img4.jpg /destination/directory/gallery/2009/11/img4.jpg
I then make the file executable and then execute it. Trouble is, the destination directories don't actually exist, so naturally, the "ln -s" fails.

Is there a way to create the destination directories dynamically based on what is specified in the file above?

I would sure appreciate any insight. Thanks in advance.
Reply With Quote
  #2  
Old 15th November 2009, 05:24 AM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
linuxfedorafirefox
Hint1: dirname takes a path and outputs the "directory name" part i.e. path with trailing "/xxx" removed.
Hint2: mkdir -p create parent directories recursively.
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.
Reply With Quote
  #3  
Old 15th November 2009, 03:18 PM
SendDerek's Avatar
SendDerek Offline
Registered User
 
Join Date: Nov 2007
Posts: 198
linuxfedorafirefox
Why is it so obvious now? haha

I appreciate that. I think it's the final key for my little project I'm working on.

Thanks again!
Reply With Quote
  #4  
Old 18th November 2009, 03:30 AM
SendDerek's Avatar
SendDerek Offline
Registered User
 
Join Date: Nov 2007
Posts: 198
macosfirefox
Wink My solution...

Well, here's what I ended up doing... it might not be the most elegant solution, but it worked for me and my script:

Code:
echo -n "Create a directory creation script..."
cat list_of_files | sed 's/^/mkdir -p "$(dirname /' | sed 's/$/)"/' > make_directories_script
echo " done"

chmod +x make_directories_script
sh make_directories_script
It changed this:
Code:
/destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0001.jpg
/destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0002.jpg
/destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0003.jpg
/destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0004.jpg
/destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0001.jpg
/destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0002.jpg
/destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0003.jpg
/destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0004.jpg
To this for execution:
Code:
mkdir -p "$(dirname /destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0001.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0002.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0003.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/11\ -\ November\At\ the\ beach\IMG0004.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0001.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0002.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0003.jpg)"
mkdir -p "$(dirname /destination/derek/pictures/2009/12\ -\ December\Snowboarding\IMG0004.jpg)"

Last edited by SendDerek; 18th November 2009 at 03:35 AM.
Reply With Quote
Reply

Tags
automatic, directory structure, directory tree, dynamic, symlink

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory Hierarchy Structure lord loh. Using Fedora 8 19th May 2007 09:58 AM
Why complicated directory structure in Linux voipfc Using Fedora 4 1st October 2006 04:41 PM
fc5 directory structure j2thet Using Fedora 3 28th March 2006 09:57 AM
Is Directory Structure Broken in FC4? MrMoke Using Fedora 7 4th July 2005 04:37 PM


Current GMT-time: 19:55 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat