37

What is the difference between the following commands?

ssh myhostname "command1; command2;...commandn;" 2>/dev/null
ssh myhostname "command1; command2;...commandn;" 
  1. what does 2> mean?

  2. what does /dev/null mean? I read somewhere that result of command will be write to file /dev/null instead of console! Is it right? It seems strange for me that the name of file be null!

Kara
  • 6,115
  • 16
  • 50
  • 57
Sepehr Samini
  • 963
  • 4
  • 11
  • 15
  • 1
    1. `man bash` is an interesting reading. 2. `/dev/null` is a special file that acts as a black hole; it doesn't take any disk space because everything that is put in it is actually discarded. – axiac Jul 27 '17 at 09:50

5 Answers5

54

2> means "redirect standard-error" to the given file.

/dev/null is the null file. Anything written to it is discarded.

Together they mean "throw away any error messages".

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
14

1 is stdout. 2 is stderr.

Then sometimes you find 2>&1, that means redirecting stderr to stdout.

Jimmy
  • 1,699
  • 2
  • 16
  • 17
5

/dev/null essentially means "into the void", discarded. The 2 you mention refers to error output, where it should be directed.

Madbreaks
  • 19,094
  • 7
  • 58
  • 72
3

2> means sending standard error to something

/dev/null means a bin

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
2

1) Pipe everything on standard error to /dev/null (so ignore it and don't display it)

2) Dev null just points to nowhere, pipe anything to that, and it disappears.

BrenanK
  • 667
  • 5
  • 4