What is the purpose of the "/dev/null" path in some commands?

Asked

Viewed 2,988 times

11

Many times, I have seen some people teaching to do some commands (mainly related to text outputs or things like), where is used this directory or file called /dev/null.

Example:

  wget -qO- $url &> /dev/null
  • What is the purpose of this /dev/null?
  • What is it? A directory or a file?
  • Why do some commands (like in the example above) use it?
  • 8

    the black hole linux? everything that goes to it goes to :D

  • What’s the problem with the question? What can be improved?

  • 1

    I saw no problems in the question. By the way, it’s a great question and what developers in general should know. After all, it is part of the WEB development to know what server wget is for and why /dev/null is used in this case.

1 answer

14


Before the technical explanation, a metaphor. Know when you send an email to a large company complaining about a product and get absolutely no response, this is the famous case where your email fell on /dev/null, that is, someone saw it and left it there (or probably didn’t see it) and you didn’t have your answer.

The /dev/null is a special file. You can redirect outputs to this device and the content will be intentionally discarded. The redirect to the /dev/null always reports success in writing.

As stated by @Guilhermelautert in the comments, the /dev/null is known as the Black Hole because of this.

In the context of the example of wget, the /dev/null is used as it is not necessary to download the content to a file, the goal is only to make a request for a certain URL. The content will obviously be transmitted from the server to the computer that ran wget, but as there is the -O in command, the output will be redirected to the /dev/null.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.