# more details about rm command needed



## aksis (Jan 15, 2015)

I know rm(1) was retooled a while back with some safety features, and now flags `rm -rf /` as an error. I am wondering if it's safety features also flags other attempts to do something similar as errors as well. For example:
`cd /; rm -rf *`
`cd /var; rm -rf ../`
etc.

Also, will it catch these types of things in a script?

Thanks.


----------



## junovitch@ (Jan 15, 2015)

If you've got a VM around make a snapshot and see.  You'll find it doesn't catch those as errors and breaks the VM nicely.  If you look at the code at line 542 you'll see the warning and line 531 just shows it's a basic check for just an attempt to delete /.

http://svnweb.freebsd.org/base/head/bin/rm/rm.c?view=markup


----------



## aksis (Jan 16, 2015)

junovitch,

Thanks for the link directly to the code, that's exactly what I was looking for, but I don't know enough about programing to hunt down sections of the 'real' documentation like that.

As an aside, how cumbersome would it be to evolve rm(1) to check if the present working directory is / AND if * is a parameter, or, if ../ would point to /, etc..?

Perhaps this has already been discussed elsewhere and it's over kill, or implementing it would be more complicated then a few lines of code.


----------



## SirDice (Jan 16, 2015)

aksis said:


> As an aside, how cumbersome would it be to evolve rm(1) to check if the present working directory is / AND if * is a parameter, or, if ../ would point to /, etc..?


With csh(1) (and tcsh(1)) there's `set rmstar`:


```
dice@molly:~ % cd test/
dice@molly:~/test % ll
total 0
dice@molly:~/test % touch file1
dice@molly:~/test % touch file2
dice@molly:~/test % ll
total 1
-rw-r--r--  1 dice  dice  0 Jan 16 08:40 file1
-rw-r--r--  1 dice  dice  0 Jan 16 08:40 file2
dice@molly:~/test % rm *
dice@molly:~/test % touch file1
dice@molly:~/test % touch file2
dice@molly:~/test % set rmstar
dice@molly:~/test % rm *
Do you really want to delete all files? [n/y] y
```


----------

