Sepehr Samini
Sepehr Samini

Reputation: 1055

What does "/dev/null" mean at the end of shell commands

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!

Upvotes: 46

Views: 53731

Answers (5)

Jimmy
Jimmy

Reputation: 1749

As mentioned in I/O Redirection:

  • 1 is the file descriptor for standard output
  • 2 is the file descriptor for standard err.

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

Upvotes: 18

Madbreaks
Madbreaks

Reputation: 19549

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

Upvotes: 9

Ed Heal
Ed Heal

Reputation: 60027

2> means sending standard error to something

/dev/null means a bin

Upvotes: 4

BrenanK
BrenanK

Reputation: 675

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.

Upvotes: 2

Michael Lorton
Michael Lorton

Reputation: 44426

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".

Upvotes: 65

Related Questions