LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-28-2003, 01:41 PM   #1
sybariten
LQ Newbie
 
Registered: Jun 2003
Location: Peking, Sweden
Posts: 6

Rep: Reputation: 0
I need help with this little bash-maneuvre


Hi all,
i'm a new user here and although i'm maybe not a real newbie, i didn't know which other of the forums to use, Software just didnt feel right.

Anyhow. I have files with identical names, eg "TheSong.mp3", spread out over dirs with similar names, eg "Folder01", "Folder02", "Folder03" etc.
Now i want to move all these files into the same folder, but in order to avoid too much fighting i figured i'd give them unique names.
My question concerns this renaming. Just by heart i thought maybe the parent folder, or should i say, the folder that the file resides in, could be a good name to add to the current filename. The result would be something like "Folder01_TheSong.mp3", "Folder02_TheSong.mp3", etc

I have this vague idea that i could position myself in root (just above the Folder0x) and use find to find the files, and then sortof pipe them through... well... xargs or something. Well not really piping. But if i remember correctly, xargs is used to do things on found files. Or, i could go a bit fancier perhaps and make some kind of for-loops that checks into each folder and does the dirty work. In any case, i'm gonna need some sort of reference to the folder-name. is there a variable such as $pwd that could be used?

All ideas are appreciated....
(.... but if you're gonna answer "RTFM" or "go to tldp.org" or something like that, please just ignore this post mmmmkay?)

Oh by the way, the folders are empty except for these files, one file in each folder.

peace!
 
Old 06-28-2003, 02:15 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Code:
for i in `find -name $1 -printf '%P\n'`
do
  mv -v $i `echo $i | tr '/' '_'`
done
 
  


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
$LINENO can't be modified in bash 3.0, while it can be in bash 2.05b Darwish Linux - Software 1 11-07-2005 02:57 PM
bash + html + javascript or just bash ? rblampain Programming 4 12-01-2004 07:53 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
Bash marco271 Programming 6 07-19-2003 04:30 PM
Bash? TheCyberDude Linux - Newbie 3 01-30-2002 02:14 PM

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

All times are GMT -5. The time now is 02:44 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
Open Source Consulting | Domain Registration