Re: /dev/null
From: Tony Walton (tonywalton_at_beeteeconnect.com)
Date: 05/31/04
- Previous message: UNIX admin: "Re: ufsdump (update)"
- In reply to: Tej: "/dev/null"
- Next in thread: Huge: "Re: /dev/null"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: UNIX admin: "Re: ufsdump (update)"
- In reply to: Tej: "/dev/null"
- Next in thread: Huge: "Re: /dev/null"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|