Re: /dev/null
From: Richard L. Hamilton (Richard.L.Hamilton_at_mindwarp.smart.net)
Date: 05/31/04
- Next message: UNIX admin: "Re: ufsdump (update)"
- Previous message: Fredrik Lundholm: "Re: HPDAT 40 driver for Intel Solaris 9"
- In reply to: Dave Saville: "Re: /dev/null"
- Next in thread: Tony Walton: "Re: /dev/null"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 May 2004 10:20:19 -0000
In article <qnirqrrmrrbet.hykx7e3.pminews@text.news.ntlworld.com>,
"Dave Saville" <dave@no-spam-deezee.org> writes:
> On 31 May 2004 00:08:01 -0700, Tej wrote:
>
>>
>>
>>Hello All,
>>
>>Would applercaite if someone can tell me about /dev/null
>>
>>1) what is /dev/null
>>2) Since rm also removes why we use /dev/null ?
>>3) what will happen if we use 2> /dev/null ? , /dev/null 2>&1
>>
>>Can any one give some of exapmles of usage /dev/null ?
>
[...]
> It can also be used to truncate an open file. Say you have a logging
> process that runs for ever. The log file will grow and grow. Solution:
>
> cp foo.log foo.log.bak
> cat /dev/null > foo.log
>
> foo does not know anyone is messing with his open files and the log
> stays a manageable size.
>
> Secondary to that, if you rm a huge open log file you still don't get
> the space back, but the /dev/null trick does.
That has nothing to do with /dev/null and everything to do with the
shell opening foo.log with the O_TRUNC flag when > is used. You might
better (in sh or ksh) use just
> foo.log
or in csh, use
: > foo.log
( ":" being a builtin command that does nothing, unlike cat /dev/null,
which has to load the command, open /dev/null, and read it only to
discover that it hits EOF immediately). In csh, if noclobber is set,
and the file exists and isn't empty, you have to show that you really
mean it by using
: >! foo.log
instead.
cat /dev/null >foo.log
isn't quite as bad as
cat file | command
(when one could just do command < file ) but it's still making more work
for the system than is needed.
-- mailto:rlhamil@smart.net http://www.smart.net/~rlhamil
- Next message: UNIX admin: "Re: ufsdump (update)"
- Previous message: Fredrik Lundholm: "Re: HPDAT 40 driver for Intel Solaris 9"
- In reply to: Dave Saville: "Re: /dev/null"
- Next in thread: Tony Walton: "Re: /dev/null"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|