LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-18-2005, 04:30 PM   #1
snorky
LQ Newbie
 
Registered: Aug 2003
Location: upper left corner, US of A
Distribution: several
Posts: 15

Rep: Reputation: 1
BASH help


I need to frequently sweep through thousands of files and delete all of those files with the .sav file extension.

If I execute this command, I can find all of those files in a few seconds:

[admin .sites]$ ls -lR * | grep "sav"

-rwxrwxr-x 1 nobody users 27 Sep 3 2004 index.shtml.sav
-rwxrwxr-x 1 nobody users 29 Sep 3 2004 paws2.gif.sav
-rwxrwxr-x 1 nobody users 29 Sep 3 2004 paws.gif.sav
-rwxrwxr-x 1 nobody users 27 Sep 3 2004 Waterlilies.jpg.sav
-rwxrwxr-x 1 nobody users 27 Sep 3 2004 volunteerluncheon.htm.sav
-rw-r--r-- 1 cwarren users 25 Feb 16 11:00 nwms_honor_roll.htm.sav
-rw-r--r-- 1 cwarren users 21 Jan 11 12:57 new_page_template.htm.sav
-rw-r--r-- 1 cwarren users 27 Feb 23 14:39 7thGradeSyllabus.htm.sav
-rw-r--r-- 1 cwarren users 23 Jan 3 14:22 new_page_template.htm.sav
-rw-r--r-- 1 cwarren users 199 Dec 6 08:51 technology.htm.sav

There are thousands more - spread over hundreds of subdirectories - not shown here. They breed like rabbits and are not just useless, they are a hinderence; I get several calls per week from users whose actions can get tangled up with those .sav files.

How can I delete the .sav files globally, without having to confirm any deletions, but without risking any non-.sav files?

A script would be fine, but I'd rather do it with a simple BASH command if it's possible.

TIA
- snorky
The names have been changed to protect the innocent.
 
Old 03-18-2005, 04:46 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Try this...
Code:
find . -depth -type f -name '*.sav' -exec rm {} \;
 
Old 03-18-2005, 05:58 PM   #3
snorky
LQ Newbie
 
Registered: Aug 2003
Location: upper left corner, US of A
Distribution: several
Posts: 15

Original Poster
Rep: Reputation: 1
BASH

homey suggested

Code:
find . -depth -type f -name '*.sav' -exec rm {} \;
Thanks homey. Unfortunately, it doesn't delete anything.

I ran that from the "top" directory of the tree that contains those pesky .sav files. The process runs in a nanosecond or so, and completely mute. Perhaps the code needs a bit more tweaking?


But I find that code intriguing.

Why are there curly braces after the rm command?

Why is there nothing inside the braces?

Is there a situation - perhaps using some other shell command - where one would put something inside the braces? Perhaps an argument for chmod or chown?
 
Old 03-18-2005, 07:27 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
That should have worked. I ran it as root user ( su - ) . Also, you may need to use the force option like this...
Code:
find . -depth -type f -name '*.sav' -exec rm -f {} \;
I don't have the official story behind the braces {} but basically, it means any files that the find command finds. The space and \ are needed to complete the command.
I haven't had a situation to put anything inside the braces but I seem to recall seeing it before.
There is another example in my collection where there are two sets of braces...
Code:
find . -type f -name '*.gif' -exec cp {} /home/new/{} \;
 
  


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 On
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 Echo Kilo Linux - General 3 11-02-2005 11:11 PM
bash help brianbek Linux - General 2 04-03-2005 06:03 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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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