LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2008, 02:16 AM   #1
dragos19
LQ Newbie
 
Registered: Aug 2006
Location: los angeles
Distribution: centos, mac os x
Posts: 17

Rep: Reputation: 0
Question 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.
 
Old 03-24-2008, 04:09 AM   #2
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Rep: Reputation: 15
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
 
Old 03-24-2008, 10:55 AM   #3
dragos19
LQ Newbie
 
Registered: Aug 2006
Location: los angeles
Distribution: centos, mac os x
Posts: 17

Original Poster
Rep: Reputation: 0
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.

Last edited by dragos19; 03-24-2008 at 10:56 AM. Reason: error in writing
 
Old 03-24-2008, 07:54 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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
 
Old 03-25-2008, 12:41 AM   #5
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Rep: Reputation: 15
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 !
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create symbolic link to html file and avoid page link problem? haxpor Linux - General 2 01-29-2008 07:40 AM
Can't create symbolic link to foxfire kiasta Ubuntu 4 01-01-2007 02:25 PM
How do I create a symbolic link? Arenba Linux - Newbie 4 09-29-2003 10:40 AM
How to create a Symbolic Link? sikandar Linux - Software 6 09-09-2003 11:41 AM
how do I create a symbolic link? rdaves@earthlink.net Linux - Newbie 2 05-23-2001 01:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration