Xref: utzoo comp.unix.xenix.sco:1201 comp.unix.shell:1152 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!cbnewsh!hosmsb!msb From: msb@hosmsb.ATT.COM (Mike Balenger) Newsgroups: comp.unix.xenix.sco,comp.unix.shell Subject: Re: emptying a file and keeping its ownership Message-ID: <1990Dec31.162555.13541@cbnewsh.att.com> Date: 31 Dec 90 16:25:55 GMT References: <1990Dec30.220722.29050@jarvis.csri.toronto.edu> Sender: msb@cbnewsh.att.com (michael.s.balenger) Reply-To: msb@hos1cad.ATT.COM (Mike Balenger) Distribution: na Organization: AT&T Bell Laboratories -- Holmdel, NJ Lines: 49 In-Reply-To: ckchee@dgp.toronto.edu's message of 31 Dec 90 03:07:23 GMT >>>>> On 31 Dec 90 03:07:23 GMT, ckchee@dgp.toronto.edu (Chuan Chee) said: ckchee> I have SCO Xenix 2.2.3. What's the easiest way to "empty" a ckchee> file while keeping its ownership (owner,group) and access ckchee> permissions the same? Actually I only care about permissions ckchee> (rw-rw-rw). I would like this done in Bourne shell (or ckchee> possibly CSH). One other thing, this shell script is run ckchee> under root. ckchee> Here's the way I currently do it: ckchee> rm -f $FILE ckchee> touch $FILE ckchee> chmod +w $FILE ckchee> chown $OWNER $FILE ckchee> chgrp $GRP $FILE This works in ksh and sh on SysV. I guess it should work for other UNIX look-alike's and shell look-alike's. > $FILE Since you don't remove the file, you don't need to recreate it. The file is truncated as a consequence of the defined behavior of output redirection, but since there is no command, no output is generated into the file. An added bonus, this method preserves links. They are lost with the "rm" in your original solution. You must, of course, have write permission to the file to try this. If that doesn't suite your fancy, try this > $FILE && { some machinations on ">", "mv", "cp" & "chmod" } The assorted machinations will only happen if the redirection fails -- most likely due to lack of write permission. This probably isn't a problem if you run a root, but may be useful for less-than-root uses. Note that the modification time is not changed if the file was already zero length. If you need that behavior, add touch $FILE -- ---------------------------------------------------------------------- Michael S. Balenger (908) 949-8789 AT&T Bell Labs FAX: (908) 949-7512 M_Balenger@att.com Room 1L-405 msb@hos1cad.att.com Crawfords Corner Road att!hos1cad!msb Holmdel, NJ 07733-1988