Re: /dev/null

From: Tony Walton (tonywalton_at_beeteeconnect.com)
Date: 05/31/04

  • Next message: Tony Walton: "Re: what version of solaris"
    Date: Mon, 31 May 2004 11:21:24 +0000 (UTC)
    
    

    On 2004-05-31 08:08:01 +0100, tksingla@hotmail.com (Tej) said:

    > Hello All,
    >
    > Would applercaite if someone can tell me about /dev/null
    >
    > 1) what is /dev/null

    It's a "bit bucket". Anything written to /dev/null doesn't go anywhere
    (it's effectively thrown away) and attempts to read from /dev/null
    simply return EOF.

    > 2) Since rm also removes why we use /dev/null ?

    Because the use of /dev/null to "null out" the content of a file is
    only one effect of what /dev/null is for.
    "cat /dev/null > foo" just relies upon the second behaviour above -
    reading /dev/null returns EOF. This isn't the same as rm-ing the file
    in any case.

    > 3) what will happen if we use 2> /dev/null ?

    Presumably you mean "somecommand 2>/dev/null". This takes output on
    stderr (file descriptor 2) and drops it in the bit bucket. The stderr
    descriptor is usually used for error messages from commands, so the
    construction means "don't show me any errors".

    For instance, in a directory containing two files, "bar" and "foo":

    Force ls to produce an error message (by trying to ls a nonexistent file):

    $ ls bar foo afile
    ls: afile: No such file or directory
    bar foo

    Same thing with stderr thrown away:

    $ ls bar foo afile 2>/dev/null
    bar foo
    $

    > ? , /dev/null 2>&1

    Again, assuming you mean "somecommand > /dev/null 2>&1"

    This says two things. First, send stdout to /dev/null (throw away
    non-error output), then send stderr to wherever stdout is pointing
    (that is, send error output to /dev/null). Use when you don't want to
    see any output at all (you may be testing the return status of the
    command later to see if it worked).

    > Can any one give some of exapmles of usage /dev/null ?

    I think you can do that bit of your homework yourself.

    -- 
    Tony
    

  • Next message: Tony Walton: "Re: what version of solaris"

    Relevant Pages

    • Re: what is difference between stdout and stderr ?
      ... log file or to syslog, not /dev/null, IMO. ... Because you know what error messages you're expecting, ... grep pattern */* | grep otherpattern ... Those whines go to stderr, so redirecting stderr to /dev/null will give ...
      (comp.lang.c)
    • Re: silencing latex (quiet/batch mode)?
      ... of emitting error messages to stderr. ... lua has access to stderr, and LuaTeX has access to lua, so the poster ... error messages to stderr, which doesn't happen with this command ...
      (comp.text.tex)
    • Re: stream io in c
      ... Typically only error messages are sent to stderr. ... However here he is keeping track of file statuses on stderr, ... and the actual output could be to stdout. ...
      (comp.lang.c)
    • Re: Nonblocking IO read
      ... the stderr stream before the command exited, ... If you're just reading one stream while the command is ... it's helpful to keep error messages out of your stdout stream. ...
      (comp.lang.ruby)