![]() |
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. |
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 |
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. |
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 |
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 |
| All times are GMT -5. The time now is 07:00 PM. |