Script to create softlink for specific file in every dir

Forum rules
Before you post please read how to get help
c.monty
Level 1
Level 1
Posts: 38
Joined: Tue Apr 26, 2011 4:23 am

Script to create softlink for specific file in every dir

Postby c.monty » 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

User avatar
xenopeek
Level 23
Level 23
Posts: 19224
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

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

Postby xenopeek » 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
Image


Return to “Scripts & Bash”

Who is online

Users browsing this forum: No registered users and 1 guest