Re: /dev/null

From: Dave Saville (dave_at_no-spam-deezee.org)
Date: 05/31/04


Date: Mon, 31 May 2004 08:54:50 +0100 (BST)

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 is usually used to throw away output from a command.

foo >/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.

HTH

--
Regards
Dave Saville
NB Remove no-spam- for good email address


Relevant Pages

  • Re: How to get the inode number of an open file
    ... there is no way that an open file can be replaced ... >> without your application knowing. ... >Care to expand on that? ... >log file with the original name, and my program just gets stuck ...
    (comp.os.linux.development.apps)
  • Re: About newsyslog behavior
    ... >> I am using the newsyslog utility to turn over my log files ... >> facts) I have confirmed that newsyslog actually creates a new log file ... >> does not affect the logging of most processes (surely not the logging ... > question is holding an open file decriptor on the log file by use of ...
    (freebsd-questions)
  • Re: /dev/null
    ... > It can also be used to truncate an open file. ... The log file will grow and grow. ... which has to load the command, open /dev/null, and read it only to ... In csh, if noclobber is set, ...
    (comp.unix.solaris)
  • Re: About newsyslog behavior
    ... That's 'SIGHUP', although I do like the idea of the kernel singing to ... > facts) I have confirmed that newsyslog actually creates a new log file ... question is holding an open file decriptor on the log file by use of ...
    (freebsd-questions)
  • Re: How to get the inode number of an open file
    ... there is no way that an open file can be replaced ... Care to expand on that? ... log file with the original name, and my program just gets stuck ...
    (comp.os.linux.development.apps)