LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find file and create a symbolic link (https://www.linuxquestions.org/questions/linux-newbie-8/find-file-and-create-a-symbolic-link-630166/)

dragos19 03-24-2008 02:16 AM

find file and create a symbolic link
 
this should be easy, but i think i am missing a fundamental piece of knowledge so i can't even conceptualize what i need to do. here is what i want to do:

in a folder that has many other sub folders, i would like to find all the mp3 files (recursively), and then create hard links to those files in another folder. the hard links would all be in a single folder, not sub folder like before. so far i know this command gives me the type f list i am looking for:

find . -name *.mp3

now i can i cover those results to links in another folder.

livetoday 03-24-2008 04:09 AM

small bash script will do....

for i in $(find /path/to/locate -iname *mp3); do j=$(basename $i); ln $i /path/to/save/$j ;done

dragos19 03-24-2008 10:55 AM

thanks livetoday, it worked, but i ran into problems. what is happening is that it script is interpreting each space in the file name as a separate file. so if the song is called "Back in Black", then it wants to make a link for Back, in and Black. the following error occurs:


ln: Back: No such file or directory
ln: in: No such file or directory
ln: Black: No such file or directory

what i am trying to move my iTunes music to a web based player. iTunes has its own way of renaming stuff.

gilead 03-24-2008 07:54 PM

Have you tried quoting the variables? For example:
Code:

for i in $(find /path/to/locate -iname *mp3); do j=$(basename "$i"); ln "$i" "/path/to/save/$j" ;done

livetoday 03-25-2008 12:41 AM

Yeah ! gilead is right....code needs quotes .. I keep forgetting it :(

You also need to quote find command as below:

Code:

for i in "$(find /path/to/locate -iname *mp3)"; do j=$(basename "$i"); ln "$i" "/path/to/save/$j" ;done
Enjoy !


All times are GMT -5. The time now is 04:23 AM.