I have a rm *.o command in Makefile to remove all the object files generated during compilation. However some error information will be output if some .o file does not exist. So how can I suppress the error information output?
In the context of make, more importantly than the output, you don't want make to treat the result of rm as failure. There are two ways to deal with it:
clean:
    -rm *.o    2> /dev/null
    rm -f *.o  2> /dev/null
The first way is to prefix the command with a minus sign, which tells make to ignore the return code. This is the preferred, make-specific way. The second is to use the -f flag, which is specific only to rm.
On top of that, you can choose to suppress the output with 2> /dev/null or not.
In rare instances, it may also be necessary to redirect the output to /dev/null. You probably want to do rm *.o > /dev/null 2>&1. The > /dev/null part sends stdout to /dev/null and the 2>&1 says to send stderr to wherever stdout is going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With