LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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, 03: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, 05: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, 11: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 11:56 AM. Reason: error in writing
 
Old 03-24-2008, 08:54 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
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, 01: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:40 AM
Can't create symbolic link to foxfire kiasta Ubuntu 4 01-01-2007 03:25 PM
How do I create a symbolic link? Arenba Linux - Newbie 4 09-29-2003 11:40 AM
How to create a Symbolic Link? sikandar Linux - Software 6 09-09-2003 12:41 PM
how do I create a symbolic link? rdaves@earthlink.net Linux - Newbie 2 05-23-2001 02:28 PM


All times are GMT -5. The time now is 09:51 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration