| Author |
remove all instances of a file
|
|
| laredotornado@zipmail.com 2007-02-23, 1:18 pm |
| Hi,
I know a file "badfile.txt" occurs several times in various
directories and sub-directories. I would like to remove it from all.
If I can isolate the upper most directory to search, how would I do
this?
I'm on Fedora Core Linux using bash.
Thanks, - Dave
| |
| Ron Hardin 2007-02-23, 1:18 pm |
| laredotornado@zipmail.com wrote:
>
> Hi,
>
> I know a file "badfile.txt" occurs several times in various
> directories and sub-directories. I would like to remove it from all.
> If I can isolate the upper most directory to search, how would I do
> this?
>
> I'm on Fedora Core Linux using bash.
>
> Thanks, - Dave
in the topmost such directory
find . -name badfile.txt -print > temp
(look at temp and verify that you like the list, then)
rm `cat temp`
like to live dangerously?
find . -name badfile.txt -print | xargs rm
--
Ron Hardin
rhhardin@mindspring.com
On the internet, nobody knows you're a jerk.
| |
| Bo Yang 2007-02-24, 1:23 am |
| Ron Hardin :
> laredotornado@zipmail.com wrote:
>
> in the topmost such directory
>
> find . -name badfile.txt -print > temp
> (look at temp and verify that you like the list, then)
> rm `cat temp`
>
> like to live dangerously?
>
> find . -name badfile.txt -print | xargs rm
>
find . -name badfile.txt -print0 | xargs -0 rm
I think this is more secure!
| |
| Stephane CHAZELAS 2007-02-24, 7:21 am |
| 2007-02-24, 10:08(+08), Bo Yang:
[...]
> find . -name badfile.txt -print0 | xargs -0 rm
> I think this is more secure!
ITYM
find . -name badfile.txt -print0 | xargs -r0 rm
find . -name badfile.txt -exec rm {} +
is the same except that is standard.
--
Stéphane
| |
| Daniel Rock 2007-02-24, 1:16 pm |
| Stephane CHAZELAS <this.address@is.invalid> wrote:
> find . -name badfile.txt -print0 | xargs -r0 rm
This is nonstandard.
> find . -name badfile.txt -exec rm {} +
This is standard.
If you have older GNU fileutils not conforming to the current standard you
could still use:
find . -name badfile.txt -exec rm {} \;
How much slower it is compared to the "+" variant depends how often
badfile.txt is found. In this case I would think that the performance is
limited by the I/O rate, so you won't "feel" any difference at all.
--
Daniel
|
|
|
|