Xref: utzoo comp.unix.xenix.sco:1475 comp.unix.shell:1332 Path: utzoo!attcan!uunet!ns-mx!iowasp.physics.uiowa.edu!maverick.ksu.ksu.edu!zaphod.mps.ohio-state.edu!samsung!cs.utexas.edu!sun-barr!newstop!sun!amdahl!krs From: krs@uts.amdahl.com (Kris Stephens [Hail Eris!]) Newsgroups: comp.unix.xenix.sco,comp.unix.shell Subject: Re: emptying a file and keeping its ownership Message-ID: Date: 12 Jan 91 01:20:03 GMT References: <1990Dec30.220722.29050@jarvis.csri.toronto.edu> <1991Jan10.182614.20728@bronze.ucs.indiana.edu> Reply-To: krs@amdahl.uts.amdahl.com (Kris Stephens [Hail Eris!]) Distribution: na Organization: Amdahl Corporation, Sunnyvale CA Lines: 52 >I think the easiest way to do this is: >cp /dev/null That costs a fork/exec of cp... >>I have SCO Xenix 2.2.3. What's the easiest way to "empty" a file >>while keeping its ownership (owner,group) and access permissions the >>same? Actually I only care about permissions (rw-rw-rw). >>I would like this done in Bourne shell (or possibly CSH). >>One other thing, this shell script is run under root. >> >>Here's the way I currently do it: >> rm -f $FILE >> touch $FILE >> chmod +w $FILE >> chown $OWNER $FILE >> chgrp $GRP $FILE ...and that assumes that the FILE needs to be umask permissions plus write-permission for everyone, and costs five fork/execs. It also requires whatever processing preceeded the sample code to determin OWNER and GRP. Ideally, that processing would have included a setting of MODE so that the chmod +w $FILE would be replaced with a chmod $MODE $FILE to maintain the mode. What I usually do is : > $FILE at least in a SVR3 system, the permissions and ownerships are maintained. (I tested this by: echo a > junk; chmod 666 junk; chown someone_else junk; : > junk -- the ls -l junk results were unchanged across the : > junk command. My umask is 022.) Execution is controlled based on all applicable file permissions, and you don't go through a possibly long (from a computer's time sense) period when the file either doesn't exist at all or exists with root and root's current group and the wrong mode. Remember, too, that the datablocks for the file won't actually be freed until all processes using the file at the outset are finished. (Which is to say that if a process has it open on write, the old file will continue to grow until that other process is complete and the open-count on the file goes to 0; only *then* will you gain your disk-space back.) This is true regardless of the method applied for zeroing the contents out. ...Kris -- Kristopher Stephens, | (408-746-6047) | krs@uts.amdahl.com | KC6DFS Amdahl Corporation | | | [The opinions expressed above are mine, solely, and do not ] [necessarily reflect the opinions or policies of Amdahl Corp. ]