4

What is the difference between

rm executable

and

rm executable >>dev/null

I had the later statement in a Makefile and changed it to the first one. I had the impression that nothing changed.

7
  • Do you mean rm executable &> /dev/null instead? What you wrote should not work.
    – Byte Commander
    Jun 30, 2016 at 19:10
  • If something is piped to /dev/null it means any messages that would be seen in the terminal are not shown since they are piped no to the ouput but to nirvana the /dev/null
    – Ziazis
    Jun 30, 2016 at 19:11
  • @heemayl Only if you do not omit the slash at the beginning of /dev/null. And I think rm will mainly produce messages on STDERR, so that would not be very useful.
    – Byte Commander
    Jun 30, 2016 at 19:21
  • 2
    rm a >>dev/null appends only stdout to a local file called null in a local directory called dev. What you probably meant is rm a &> /dev/null which redirects both stdout and stderr to the special character device /dev/null.
    – cat
    Jun 30, 2016 at 21:34
  • 1
    @cat Please don't suggest the use of bashisms. rm a > /dev/null 2>&1 is the portable construct.
    – zwol
    Jun 30, 2016 at 23:46

2 Answers 2

8
rm executable

simply deletes the file executable from the current directory.

rm executable &> /dev/null

does the same, but it runs the command with output and error streams redirected to the special file /dev/null.

That means you will not see any messages in the terminal. The /dev/null file they are redirected to instead is a virtual character device which simply swallows all incoming data like a black hole.

Output redirection to /dev/null like this is often used in scripts where you don't want the user to see possible output of the contained commands.

2
  • But don't black holes emit radiation !?! :D
    – geek1011
    Jun 30, 2016 at 23:31
  • 2
    @geek1011 /dev/null usually doesn't. However, quoting Wikipedia: "The April Fool's, 1995 issue of the German magazine c't reported on an enhanced /dev/null chip that would efficiently dispose of the incoming data by converting it to a flicker on an internal glowing LED."
    – nanofarad
    Jun 30, 2016 at 23:38
4

This append line to /dev/null only means that all output is omitted or better to say send directly into the data nirvana (or void, or bottomless pit). So the only thing that could change is that if this command runs into an error that you will see output for it on the screen.

4
  • Nirvana? I... don't think you know what that word means :P I've never heard /dev/null called that, but "void" or "bottomless pit" might be better
    – cat
    Jun 30, 2016 at 21:39
  • @cat nirvana, from Skt. nirvana-s: "extinction, disappearance" (of the individual soul into the universal), lit. "to blow out, a blowing out" ("not transitively, but as a fire ceases to draw;" a literal Latinization would be de-spiration), from nis-, nir- "out" + va "to blow". So still a perfect fit :), but I'll add your suggestions into my answer.
    – Videonauth
    Jun 30, 2016 at 21:51
  • "You don't know the definition of that word," I tell someone on the internet, not having actually recently looked up that word. For some reason I thought it means "heaven" or "peaceful place" whatever, I dunno
    – cat
    Jun 30, 2016 at 22:14
  • 1
    It can be used in both ways, well however were not here to discuss etymology of words :) you're not wrong to think it means freedom of pain (or heaven) but can be used as it is as well for the opposite. It even has depending on the religion it is used in different meanings as well, see its wiki page.
    – Videonauth
    Jun 30, 2016 at 22:16

You must log in to answer this question.

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