Re: /dev/null

From: Richard L. Hamilton (Richard.L.Hamilton_at_mindwarp.smart.net)
Date: 05/31/04


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


Relevant Pages

  • Re: Save As command in Access VBA
    ... "SaveCopyAs" command, which saves a copy of the currently open file to ... for each tdf in cdb.Tabledefs ... ' correct but you can check that in the help files ...
    (microsoft.public.access.modulesdaovba)
  • Re: executing shell commands
    ... the shell command as a list of lines. ... >@ fileId FileId must be the identifier for an open file, ... Standard ...
    (comp.lang.tcl)
  • Re: running other applications
    ... Does MatLab have a command or maybe there is a way that I could write ... MatLab to supply the correct input file. ... same file name once I excute the bang command and run the other file? ... certain file into the open file window then excutes that command. ...
    (comp.soft-sys.matlab)
  • Re: File association
    ... >> Handle is targetted at searching for open file references, ... > you how to use command line utilities in this forum. ...
    (microsoft.public.windowsxp.basics)
  • Re: How to know when file is finished being written to?
    ... maybe search for an open file handle? ... There is a utility called "Handle" at www.sysinternals.com which is a command line utility that will show which processes have a file handle in use. ... That would work so long as FTP doesn't unlock/relock the file prior to completion of the download. ...
    (microsoft.public.scripting.vbscript)