Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to zero out a file in tcsh?



John,
You and I have extensive experience with most of the Unix shells. The
cat command is a standard Unix/Linux command. /dev/null is universal in
all Unix and variants. And, all Unix file systems work on the same basic
concept from a user and API standpoint. (Under the covers there are
significant differences).
The process overhead in Unix and Linux is relatively small, and with
virtual memory, there is a good chance that the cat command may already
be memory resident. Unix and Linux have a large number of small
commands. Because of that and because of virtual memory there has been a
lot of work on reducing the overhead. I maintain that the additional
overhead of loading an external command like cat is insignificant when
compared to the savings of using a shell builtin. The shell may have to
page in the echo command. 
On Fri, 07 Feb 2003 17:55:07 UTC
John Chambers <jc at trillian.mit.edu> wrote:

> Dave Gavin writes:
> |  the "rm filename; touch filename" variation doesn't necessarily
> preserve| ownership or permissions depending on who does it and what
> their umask is.| My personal favorite is "cat /dev/null > filename".
> 
> This may be the most universal, and it doesn't have the problem  with
> "rm;touch" of a window when the file doesn't exist. Is there any case
> where this wouldn't work in any unix shell?
> 
> If you're worried about the  overhead  of  the  unnecessary  process,
> there  doesn't  seem  to  be  any universal command that works in all
> known shells.  Using echo doesn't quite work, because it  produces  a
> single  \n  by  default, and there are at least two different ways of
> suppressing this character.
> 
> Isn't it amazing how much discussion it can take to figure out how to
> produce nothing, reliably?
> 
> I've always sorta liked the observation that the Arabs introduced the
> concept  of  zero  to Western Civilization around 1500 years ago, but
> most of the computer industry still hasn't caught on to the idea. The
> zero case is almost always special, and takes special code to handle.
> Unix software is usually better at this than others, but even on unix
> systems  you  run  into lots of cases where making the zero case work
> takes half the time.
> 
> I haven't worked on IBM mainframes for over 20 years now, but I  well
> remember  the  grief  caused  by the fact that closing an output file
> without writing a record was a fatal  error,  as  was  attempting  to
> write a zero-length record.  This recently bit me again, though.  I'm
> working on a project where some of the files get sent to  mainframes.
> One of the constraints is that, if my code writes \n\n, the mainframe
> (Cobol) software gets a fatal error when it attempts to deal with the
> zero-length record. So far, I haven't sent them any null files, but I
> can well imagine what that would do to their software.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20030207/f3a5ee8d/attachment.sig>



BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org