From: Michael Paoli on
$ (cd directory_to_be_emptied && rm -rf * .[!.]* ..?*)
Or if one's quite sure one's already in the desired directory:
$ m -rf * .[!.]* ..?*

On Mar 9, 12:06 am, moonhkt <moonhkt(a)gmail.com> wrote:
> Any suggestion ? Currently, I am using below shell command
> cd delete_path
> rm -f *      # remove current directory files
> rm -f */*    # remove subdirectory files
> rm -f */*/*  # repeat ...
> rm -f */*/*/*
> rm -f */*/*/*/*
> rm -f */*/*/*/*/*
> rm -f */*/*/*/*/*/*
> rm -f */*/*/*/*/*/*/*
> rm -f */*/*/*/*/*/*/*/*
> du -k | awk '{print $2}' |sort  -r |xargs rmdir -p  # remove all
> subdirectory
From: Stephane CHAZELAS on
2010-03-25, 03:39(-07), Michael Paoli:
> $ (cd directory_to_be_emptied && rm -rf * .[!.]* ..?*)
> Or if one's quite sure one's already in the desired directory:
> $ m -rf * .[!.]* ..?*
[...]

$ rm -rf -- * .[!.]* ..?*

Or:

$ rm -rf ./* .[!.]* ..?*

Or on non-GNU systems:

$ rm -rf .[!.]* ..?* *

--
Stéphane
From: bsh on
Sven Mascheck <masch...(a)email.invalid> wrote:
> Houghi wrote:
> > what I have forced myself to learn is using `rm * -rf` It somehow
> > gives me just that fraction of a second to realize what I want to
> > delete before press ENTER.
> Options after arguments is not portable [1],
> (and btw: incompatible with a terminating "--").

A simple, portable technique that has saved my butt (and my data)
more than once, is to create file "-i" in the CWD(s). Specifying
command-
line option "*" without an explicit "--" options delimiter, will, with
empty file "-i", allow one a second chance to think better of doing
so.

If not already discussed, one should also get into the habit of test-
running such inexorable commands, with an prepended "echo" command,
to obviate unforeseen consequences.

echo rm -rf * # ... or be sorry!

=Brian
From: David Combs on
In article <1f71a283-a17e-470c-9704-efc40ffd54f3(a)a10g2000pri.googlegroups.com>,
bsh <brian_hiles(a)rocketmail.com> wrote:
>Sven Mascheck <masch...(a)email.invalid> wrote:
>> Houghi wrote:
>> > what I have forced myself to learn is using `rm * -rf` It somehow
>> > gives me just that fraction of a second to realize what I want to
>> > delete before press ENTER.
>> Options after arguments is not portable [1],
>> (and btw: incompatible with a terminating "--").
>
>A simple, portable technique that has saved my butt (and my data)
>more than once, is to create file "-i" in the CWD(s). Specifying
>command-
>line option "*" without an explicit "--" options delimiter, will, with
>empty file "-i", allow one a second chance to think better of doing
>so.

For those of us not so up-to-speed on shell arg-processing,
could you please elaborate a bit on the above.

The NAME of the empty file IS "-i" -- starts with a minus-sign.

Does that put it at the beginning of the alpha-sorted file-names (assuming
there are no other such filenames in the dir)?

And, so what if it's empty -- how does that change anything?

There being no "-i" in that rm, but instead a -f, how is the rm
going to give you one final chance to change your mind about
actually doing it?

Thanks!

>
>If not already discussed, one should also get into the habit of test-
>running such inexorable commands, with an prepended "echo" command,
>to obviate unforeseen consequences.
>
>echo rm -rf * # ... or be sorry!
>
>=Brian


And please also say a bit more about your so-very-important (and crazy
not to) use of echo.

What might it show you that you can't already see by looking at
the rm-cmd itself?

What, arguments to it shown evaluated?


What disasters might you avoid via this eval?


Also, any reason to double-quote the whole rm-with-args? Would
echo's output be any different?


The above two techniques being found so necessary for avoiding
screwups/disasters in your work, please say some more,
and also give more examples (where YOU've been saved),
before we too adopt your practice.

THANKS!

David






From: Chris F.A. Johnson on
On 2010-04-12, David Combs wrote:
> In article <1f71a283-a17e-470c-9704-efc40ffd54f3(a)a10g2000pri.googlegroups.com>,
> bsh <brian_hiles(a)rocketmail.com> wrote:
>>Sven Mascheck <masch...(a)email.invalid> wrote:
>>> Houghi wrote:
>>> > what I have forced myself to learn is using `rm * -rf` It somehow
>>> > gives me just that fraction of a second to realize what I want to
>>> > delete before press ENTER.
>>> Options after arguments is not portable [1],
>>> (and btw: incompatible with a terminating "--").
>>
>>A simple, portable technique that has saved my butt (and my data)
>>more than once, is to create file "-i" in the CWD(s). Specifying
>>command-
>>line option "*" without an explicit "--" options delimiter, will, with
>>empty file "-i", allow one a second chance to think better of doing
>>so.
>
> For those of us not so up-to-speed on shell arg-processing,
> could you please elaborate a bit on the above.
>
> The NAME of the empty file IS "-i" -- starts with a minus-sign.
>
> Does that put it at the beginning of the alpha-sorted file-names (assuming
> there are no other such filenames in the dir)?

The shell expands wildcards into an alphabetically sorted list.

> And, so what if it's empty -- how does that change anything?

It doesn't.

> There being no "-i" in that rm, but instead a -f, how is the rm
> going to give you one final chance to change your mind about
> actually doing it?
>
> Thanks!
>
>>
>>If not already discussed, one should also get into the habit of test-
>>running such inexorable commands, with an prepended "echo" command,
>>to obviate unforeseen consequences.
>>
>>echo rm -rf * # ... or be sorry!
>
> And please also say a bit more about your so-very-important (and crazy
> not to) use of echo.
>
> What might it show you that you can't already see by looking at
> the rm-cmd itself?

With echo, you will see the line as it would be executed -- with
the wilcard already expanded.

> What, arguments to it shown evaluated?

Yes. The shell expands wildcards to create a list of arguments
that will be substituted on the command line.

> What disasters might you avoid via this eval?

It allows you to see exactly what would be deleted without
actually deleting anything. Once you know that the expanded list
is correct, you can remove the echo.

> Also, any reason to double-quote the whole rm-with-args? Would
> echo's output be any different?

Wildcards within quotes are not expanded.

> The above two techniques being found so necessary for avoiding
> screwups/disasters in your work, please say some more,
> and also give more examples (where YOU've been saved),
> before we too adopt your practice.


--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====