1

why below statement do not ask for confirmation while using option i or I for rm ?

// pass aggregated 
find . -name $name -type d -exec rm -irf {} \;
// pass each
find . -name $name -type d -exec rm -irf {} +

1 Answer 1

0

The -i option asks for confirmation but the -f option which follows in your command overrides it, turning off the confirmation dialog.

Observe:

$ rm -fri file1
rm: remove regular empty file 'file1'? n
$ rm -irf file1
$ 

If the first form above, -f appears first and -i latter. Consequently, -i overrides -f and rm asks for confirmation.

In the second form above, -i appears first and -f latter. In this case, -f overrides and no confirmation dialog appears.

Documentation

From man rm:

-f, --force
ignore nonexistent files and arguments, never prompt

-i
prompt before every removal

-I
prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes

3
  • 1
    so it should be only -ir or -Ir :) without forcing
    – ceph3us
    Nov 21, 2017 at 23:16
  • and what would be the best way (match) to protect from harmful delete using -I or -i and + or \; ?
    – ceph3us
    Nov 21, 2017 at 23:18
  • @ceph3us Yes, omit the -f. The option -i provides more protection than -I. If you are using -i, then find ...\; and find ...+ are both equally safe with the later being more computationally efficient.
    – John1024
    Nov 21, 2017 at 23:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .