LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-11-2006, 10:32 PM   #1
bd1308
LQ Newbie
 
Registered: Aug 2005
Location: Louisville, KY
Distribution: Debian Sarge
Posts: 29

Rep: Reputation: 15
Making shell script to 'locate' m4a files and delete them


Hello, I just added an old mac to my collection of networked computers. using atalkd and it all works. The mac will play mp3's fine, but locks-up for several minutes when trying to play m4a files.

anyway, I need some help designing a shell script to use locate to find ALL *.m4a files and then pipe it to 'rm -rf' using the output from locate as the input to rm....

i tried piping it and it didnt work out well at all...

b
 
Old 02-11-2006, 11:41 PM   #2
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
The locate program can be used with a regex, try:

Code:
rm `locate -r \.m4a$`
Of course you might want to check the output with echo first, like

Code:
echo `locate -r \.m4a$`
to make sure you're not deleting anything by mistake you want to keep. Or you can just use mv instead of rm to move them all to one directory, then examine its contents and if it's all unwanted just delete that.

BTW, those are backticks (the character under your tilda) not quote marks. They evaluate the expression inside and place it literally in the command.
 
Old 02-12-2006, 09:13 AM   #3
bd1308
LQ Newbie
 
Registered: Aug 2005
Location: Louisville, KY
Distribution: Debian Sarge
Posts: 29

Original Poster
Rep: Reputation: 15
okay, I ran the echo code and it spit out what appears to be a single line wrapped around many times...shouldn't the output be individual lines?

then I ran the main script, and it told me that there was an invalid option, a capital N..I assume this is actually a name of a folder or something, and its confusing rm?

I appreciate your help though. Thank you.

b
 
Old 02-12-2006, 10:44 AM   #4
bd1308
LQ Newbie
 
Registered: Aug 2005
Location: Louisville, KY
Distribution: Debian Sarge
Posts: 29

Original Poster
Rep: Reputation: 15
IFS="
#
";
for i in `locate -r '.*\.[mM]4[aA]'`; do
ls -l ${i}
done

that ended up fixing everything

b
 
  


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
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 04:58 AM
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
delete mail via shell script kevin_obtiva Programming 1 12-10-2005 09:24 AM
making .tif files into animated .gif files (bash shell, Red Hat 7.2) illiniguy3043 Linux - Newbie 1 06-01-2004 04:04 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:34 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