LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-28-2006, 11:12 AM   #1
chess
Member
 
Registered: Mar 2002
Location: 127.0.0.1
Distribution: Slackware and OpenBSD
Posts: 740

Rep: Reputation: 190Reputation: 190
Delete a bunch of files with "find"


I have been googling around for an answer and have tried to run several different commands without any luck.

I have imported a bunch of music files from a Mac and there are all these .DS_Store files all over the place. I want to search through my ~/music directory and delete them all. So, I found this command:

Code:
find . -name .DS_Store | xargs rm -i
the -i is to be prompted for each file deletion. Anyway, when I run this command, I get:

"rm: too few arguments"

I then saw something about adding -print0 to the find and -0 to the xargs, like this:

Code:
find . -name .DS_Store -print0 | xargs -0 rm -i
and this gives me a list of the files with a question mark at the end. Entering "yes" or "y" does not do anything.

How to do I recursively search through a directory and delete a bunch of files matching ".DS_Store"?

Thanks!
 
Old 01-28-2006, 11:52 AM   #2
mdarby
Member
 
Registered: Nov 2004
Location: Columbus, Ohio
Distribution: Slackware-Current / Debian
Posts: 795

Rep: Reputation: 30
try
Code:
find ~/music -name ".DS_Store" -print0 | xargs -0 -r rm
I would of course list the output before deleting anything:
Code:
find ~/music -name ".DS_Store" -print0 | xargs -0 -r ls -l

Last edited by mdarby; 01-28-2006 at 11:56 AM.
 
Old 01-28-2006, 12:02 PM   #3
chess
Member
 
Registered: Mar 2002
Location: 127.0.0.1
Distribution: Slackware and OpenBSD
Posts: 740

Original Poster
Rep: Reputation: 190Reputation: 190
Thanks, Matt, that worked perfectly. I guess I was missing the "-r" before the "rm".
 
Old 01-28-2006, 12:08 PM   #4
mdarby
Member
 
Registered: Nov 2004
Location: Columbus, Ohio
Distribution: Slackware-Current / Debian
Posts: 795

Rep: Reputation: 30
It was actually the quotation marks. "." in the -name clause is taken as part of a regular expression. The "-r" in the xargs part is to stop xargs from firing if it isn't passed anything (xargs by default runs once no matter what).

I always use "-print0" and "-0" as they take care of special characters in filenames.
 
  


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
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
bunch of "location" questions mdb84 Linux - Software 4 03-24-2005 02:53 PM
"Cannot find header source files" when trying to install Nvidia 6111 drivers naddad Linux - Newbie 3 08-31-2004 12:42 PM
"X-MS" cant open because "x-Multimedia System" cant access files at "smb&qu ponchy5 Linux - Networking 0 03-29-2004 11:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

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