From: Ivan Shmakov on
>>>>> houghi <houghi(a)houghi.org.invalid> writes:
>>>>> Dominic Fandrey wrote:

>> What you are looking for is the both dangerous and popular drug
>> rm -rf *

> On a sidenote, 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.

A good habit, indeed.

> It might not work everywhere, nut it des on (my) linux and
> especially when using [TAB] for completion has saved me in the
> past. e.g. if I want to delete a directory ~/none, use tab for
> completion and mistye the n for a b: rm -rf ~/b[tab][enter] The
> ENTER is almost imidiatly after the tab and I have deleted bin and
> not none.

When it comes to me, I occasionally mistype nothing for a
letter. So, it'd easily become $ rm -rf ~/ RET, if not such a
habit.

> Now if I would do `rm ~/b[tab] -rf` I would have the time of typing
> " -rf" before I hit enter and see that it says ~/bin and not ~/none.

--
FSF associate member #7257
From: jellybean stonerfish on
On Tue, 09 Mar 2010 06:35:29 -0600, Ed Morton wrote:

> On 3/9/2010 1:06 AM, moonhkt wrote:
>> Hi All
>>
>> 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
>>
>> moonhkt
>
> Genuinely curious - "rm" only has about 5 or 6 options so when you
> looked up the man page did you not understand what "recursively" meant
> or not notice it or was it something else?
>
> Ed.

The man pages may not be available in moonhkt's native language?
From: Sven Mascheck on
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 "--").

And a few times, when I noticed that it's possible at all, e.g. in GNU,
I (personally) even found that rather annoying - but obviously an "ymmv".

[1] not to confuse with find, which additionally knows "expressions".
From: Ed Morton on
On 3/9/2010 8:35 AM, jellybean stonerfish wrote:
> On Tue, 09 Mar 2010 06:35:29 -0600, Ed Morton wrote:
>
>> On 3/9/2010 1:06 AM, moonhkt wrote:
>>> Hi All
>>>
>>> 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
>>>
>>> moonhkt
>>
>> Genuinely curious - "rm" only has about 5 or 6 options so when you
>> looked up the man page did you not understand what "recursively" meant
>> or not notice it or was it something else?
>>
>> Ed.
>
> The man pages may not be available in moonhkt's native language?

Yes, but if so then neither is this NG and I'd think this from the rm man page:

-r, -R, --recursive remove directories and their contents recursively

would be at least as easy to understand as the comments the OP wrote in his script:

rm -f * # remove current directory files
rm -f */* # remove subdirectory files
rm -f */*/* # repeat ...

and the responses posted here. Like I said, I'm just curious about how a
question like this gets posted....

Ed.
From: Stephane CHAZELAS on
2010-03-9, 16:21(+01), houghi:
> Sven Mascheck 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],
>
> That is what I thought and therfore wrote that it might not work
> everywhere.
[...]

Actually, it doesn't work on Unix systems. It only works on GNU
systems if there's no POSIXLY_CORRECT variable in the
environment.

Also,

rm -rf ./*
or
rm -rf -- *

are better in case some filenames start with "-"

It should also be noted that it will not remove dot files.

zsh issues a "zsh: sure you want to delete all the files"
prompt in that very case (which you can disable), that is when
calling a "rm" command with an argument that is "*" or
"whatever/*"

In zsh, to remove every file:

rm -rf ./*(D)

(The (D) is to include the dot files except "." and "..").



--
Stéphane