Skip to content
suewonjp edited this page Oct 29, 2017 · 1 revision

rmrf - Safely delete files/folders using 'rm -rf' command

Available Since Version 0.8

✔️ Motivations

rm -rf command is convenient and powerful. It lets you delete one or more files or folders. (In case of a folder, it will recursively delete everything under that folder and the folder itself) However, using it without caution may cause a disaster.

For example, say, you wanted to type rm -rf /foo/bar, but typing in a hurry might end up like rm -rf / foo/bar, which would possibly delete the entire file system! Or when your intention was rm -rf "/foo bar/baz", but you omitted proper quoting like rm -rf /foo bar/baz, then you would end up deleting /foo not /foo bar. If you happened to have /foo, then that would possibly delete some valuable data!

rmrf is a wrapper command for rm -rf. It delegates jobs of deleting files/folders to rm -rf command, but it detects possible dangers beforehand.

Its unique behaviors are:

  1. It will deny deleting root level files/folders
    • e.g) rmrf /foo/bar will be aborted.
    • So it will keep you from mistakenly deleting root level folders.
    • Basically, you can't use rmrf to delete any of root level files/folders, so you need to use other methods to do that, but at least it will make you stay focused when deleting critical data like root level folders.
  2. It will deny deleting ../ or ./
    • e.g) rmrf ../ foo/bar will be aborted.
    • e.g) rmrf ./ foo/bar will be aborted.
    • If rmrf sees any of ../ or ./ not followed by folder names, it will abort the operation. ( Operations like rmrf ../foo/bar are OK. )
  3. It will always ask your final confirmation before actually deleting files/folders
    • This is for giving you a final chance to confirm you are deleting right ones.
    • It will highlight names of files/folders about to delete in a different color so that they are noticeable.
    • Type y to proceed or type n to abort

✔️ del= Behavior Control Variable

Using rmrf in a separate command is useful, but it also can be used in conjunction with lf or lfs or lff

Use del= Behavior Control Variable to delete files/folders found by lf or lfi like so:

    $ lf .js

    foo.js
    bar.js

    $ del= lfs

    lf.sh : Are you sure if you want to delete the following path? (y or n)
        foo.js
        bar.js
    y
    lf.sh : "foo.js" (file) deleted...
    lf.sh : "bar.js" (file) deleted...

The operation above is the same as del= lf .js