Script to create softlink for specific file in every dir

Forum rules
Before you post please read this

Script to create softlink for specific file in every dir

Postby c.monty on Wed Sep 05, 2012 3:25 am

Hello!

My music library is organised in this structure:
/music/<artist>_<album>/

In every directory there's a file named
front_<artist>_<album>.jpg

The script should search in every directory for this file and create a softlink front.jpg on it.

Can you provide some input for the syntax of a bash script?
That would be highly appreciated.

THX
c.monty
Level 1
Level 1
 
Posts: 39
Joined: Tue Apr 26, 2011 4:23 am

Linux Mint is funded by ads and donations.
 

Re: Script to create softlink for specific file in every dir

Postby xenopeek on Wed Sep 05, 2012 1:39 pm

Not so hard, just one command:
Code: Select all
find . -iname front_\*.jpg -type f -printf "\"ln -s '%f' '%h/front.jpg'\"\n" | xargs -l bash -c

Open a terminal on the music directory, and run it from there. It will find all the files beginning with front_ and ending in .jpg (case-insensitive, make it -name instead of -iname to make it a case-sensitive search). At the directory where it found those it will create a symbolic link to each and call it front.jpg. If you are in doubt, first only run the first part:
Code: Select all
find . -iname front_\*.jpg -type f -printf "\"ln -s '%f' '%h/front.jpg'\"\n"

It will give you a list of all the commands it will run to create the symbolic links.

Hack on :D
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14661
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest