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 - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-01-2005, 08:42 PM   #1
Dankles
Member
 
Registered: May 2004
Location: /dev/null
Distribution: Slackware
Posts: 245

Rep: Reputation: 31
remove *.ini in all Dirs with one command


I recently moved all 60GBs of my music from my Win box to my slackware file server.
Windoze indexing service kindly makes desktop.ini and thumbs.db automagicly in all of the directories.
Is there any way to remove all of these files with one command?
I'm know this isn't really a Slackware specific question, but you guys always give the best of answers.
something with 'find' combined with 'rm' maybe?
 
Old 11-01-2005, 08:56 PM   #2
darkarcon2015
Member
 
Registered: Jun 2004
Location: Potsdam, NY
Distribution: Fedora Core 6
Posts: 201

Rep: Reputation: 30
You can find everything in a directory and all the directories contained in it with:
Code:
find * | grep "search_phrase"
And you can remove everything with *.ini with:
Code:
rm -rf *.ini
But, I think the "-r" option of `rm` meaning recursive, will search through all directories starting with the one you are currently in.

Last edited by darkarcon2015; 11-01-2005 at 09:00 PM.
 
Old 11-01-2005, 09:40 PM   #3
Dankles
Member
 
Registered: May 2004
Location: /dev/null
Distribution: Slackware
Posts: 245

Original Poster
Rep: Reputation: 31
I tried the 'rm -r' option before with no success. I thought that the recursive thing would work because when i remove directory trees i use 'rm -dr'.
 
Old 11-01-2005, 10:53 PM   #4
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,448
Blog Entries: 7

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
How about a 'for' loop?

Code:
# find /musicdirectory | grep "desktop.ini" > temporary_file

# for i in `cat temporary_file`; do rm $i; done
Check the contents of 'temporary_file' to see what would be deleted before doing do.

Please note the use of `backticks`. On my keyboard, they're on the same key as ~.

You could probably do it all in one step, but I'd be more comfortable seeing what would be deleted first.

Last edited by rkelsen; 11-01-2005 at 10:55 PM.
 
Old 11-02-2005, 12:09 AM   #5
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
Or using just find:
Code:
find /directory -name '*.ini' -exec rm '{}' \;
 
Old 11-02-2005, 04:52 PM   #6
LiNuCe
Member
 
Registered: Apr 2004
Location: France
Distribution: Slackware Linux 10.2
Posts: 119

Rep: Reputation: 15
Quote:
gbonvehi: Or using just find:
Code:
find /directory -name '*.ini' -exec rm '{}' \;
Faster version :
Code:
find /directory -name \*.ini | xargs rm -f
--
LiNuCe
 
Old 11-02-2005, 05:28 PM   #7
raska
Member
 
Registered: Aug 2004
Location: Aguascalientes, AGS. Mexico.
Distribution: Slackware 13.0 kernel 2.6.29.6
Posts: 816

Rep: Reputation: 31
Quote:
Originally posted by LiNuCe
Faster version :
Code:
find /directory -name \*.ini | xargs rm -f
I'm not sure if that works
 
Old 11-02-2005, 05:38 PM   #8
LiNuCe
Member
 
Registered: Apr 2004
Location: France
Distribution: Slackware Linux 10.2
Posts: 119

Rep: Reputation: 15
Quote:
Originally posted by raska
I'm not sure if that works
It does work as long as *.ini files do not have space/special characters in their full pathnames, in which case the following, modified the gbonvehi's solution is the right one (at least with the BASH shell):
Code:
find /directory -name \*.ini -exec rm -f \\'{}\\' \;
--
LiNuCe

Last edited by LiNuCe; 11-02-2005 at 05:45 PM.
 
Old 11-02-2005, 06:00 PM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The find command has an option -print0 that uses a null character between filenames.
The xargs command has a corresponding -0 or --null option that uses this kind of input. This should help if the file or pathnames contain whitespace characters.

Also consider using one of the options to limit the number of files handled at a time. This is needed if you have a very large number of files output by the find command.
 
Old 11-03-2005, 08:36 AM   #10
Dankles
Member
 
Registered: May 2004
Location: /dev/null
Distribution: Slackware
Posts: 245

Original Poster
Rep: Reputation: 31
I havent had a change to test any of these yet, I've been busy with work, but i'll let all of you guys know how it worked.
thanks everyone
 
Old 11-03-2005, 08:56 PM   #11
Dankles
Member
 
Registered: May 2004
Location: /dev/null
Distribution: Slackware
Posts: 245

Original Poster
Rep: Reputation: 31
Hey all, I finally had a chance to test all of these out.

gbonvehi:
the
# find /directory -name '*.ini' -exec rm '{}' \;
command worked well

rkelsen:
I liked the For loop idea aswell, but I had to modify it to get it to work with spaces in my file names.

thanks everyone
 
  


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
command line: coloured files,dirs,etc kpachopoulos Linux - General 3 11-13-2005 04:24 PM
Terminal command for GUI command "Remove to trash" GunSkit Linux - General 3 06-29-2004 01:50 PM
remove folder from command line demmylls Linux - General 3 02-15-2004 09:52 AM
Command to remove a directory... xconspirisist Linux - Software 2 11-28-2003 01:06 PM
what is the command to remove the directory Harish_f Linux - General 6 06-19-2002 03:32 AM

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

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