-3

I'm wondering if the two commands (1) rm -rf *o and (2) rm -rf *.o give the same result: both delete the object files.

Moreover why the above commands delete the executable files as well?

Gennaro Arguzzi
  • 769
  • 1
  • 14
  • 27
  • 2
    The first command will remove any files that end with o and the second will delete all files ending with a dot and then o. – Raman Sailopal Jan 03 '21 at 15:33

2 Answers2

3

* is a shell pattern matching anything except for hidden files.

rm -rf *o will thus also delete a file called hello or test.iso, whereas rm -rf *.o will only delete files ending in .o.

By the way, -r means recursive, i.e. will delete directories too. It should not be present here. You want rm -f *.o.

phihag
  • 278,196
  • 72
  • 453
  • 469
1

I'm wondering if the two commands (1) rm -rf *o and (2) rm -rf *.o give the same result: both delete the object files.

No, they don't give the same result:

  1. Deletes all files that end with o as well as all directories that end with o.
  2. Deletes all files that end with .o as well as all directories that end with .o.

Moreover why the above commands delete the executable files as well?

Probably because they end with o (1) or .o (2).

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653