[kanchilug] [Tip] Protect directory from an overzealous rm -rf *

  • From: "Tha.Suresh" <jemenisuresh@xxxxxxxxx>
  • To: ILUG-C <ilugc@xxxxxxxxxxxxx>, Linux Delhi <iitdlug@xxxxxxxxxxxxxxxx>, ilug-bengaluru@xxxxxxxxxxxxxxxx, Mlug <glug-meerut@xxxxxxxxxxxxxxxx>, KanchiLug <kanchilug@xxxxxxxxxxxxx>, puduvailug@xxxxxxxxxxxxx
  • Date: Sat, 14 May 2011 13:07:44 +0530

 $ cd <directory>; touch ./-i

Forces the -i flag on the rm command when using a wildcard delete.

The ‘–’ option tells it to stop looking for flags and treat the rest of the
command line as operands.

Note that this trick won’t work if you specify an absolute path (as in *rm
-rf ~/linux/*) — only when you are within the directory. I’d recommend
dropping this in your home and / directories.


Ex:

[suresh@mercury ]$ cd linux; touch ./-i
[suresh@mercury linux]$ rm -rf *
rm: remove regular empty file `test'? n
rm: remove regular empty file `thasu'? n
rm: remove regular empty file `ubuntu'? n


-- 
Warm Regards,
Tha.Suresh


My experiences with Linux: http://thasulinux.wordpress.com

Cooool Linux Tips & Tricks:http://gnutips.wordpress.com

Free/Open Source Jobs: http://fossjobs.in

Other related posts:

  • » [kanchilug] [Tip] Protect directory from an overzealous rm -rf * - Tha.Suresh