Xref: utzoo comp.unix.xenix.sco:1222 comp.unix.shell:1159 Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cstreet!john From: john@cstreet.com (John Poplett) Newsgroups: comp.unix.xenix.sco,comp.unix.shell Subject: Re: emptying a file and keeping its ownership Summary: How to truncate files from a Bourne shell script. Keywords: truncating files, bourne shell Message-ID: <1990Dec31.201951.1140@cstreet.com> Date: 31 Dec 90 20:19:51 GMT References: <1990Dec30.220722.29050@jarvis.csri.toronto.edu> Reply-To: john@cstreet.UUCP (John Poplett) Distribution: na Organization: C Street Software @ cstreet.com Lines: 71 In article <1990Dec30.220722.29050@jarvis.csri.toronto.edu> ckchee@dgp.toronto.edu (Chuan Chee) writes: >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. > The simplest way to truncate a file using the Bourne shell is: > file Here's a short Bourne shell script that truncates files. Cut it out and save it to trunc.sh and run "make trunc" to get an executable script file. John ------ cut here -------- cut here -------- cut here -------- : # @(#)trunc.sh -- truncate or create empty files. Optionally, setting # owner or group ID. usage() { echo "usage: $0 [-o owner] [-g group] file1 [file2...]" 1>&2 exit 1 } if [ $# -lt 1 ] then usage fi set -- `getopt g:o: $*` if [ $? != 0 ] then usage fi for i in $* do case $i in -g) group=$2; shift; shift;; -o) owner=$2; shift; shift;; --) shift; break;; esac done for file in $* do > $file done if [ $group ] then chgrp $group $* fi if [ $owner ] then chown $owner $* fi exit 0 -- John Poplett @ C Street Software | Never make forecasts, especially 312 Wolff St. Oxnard, Ca. 93033 USA | about the future. (805) 486-7807 / john@cstreet.com | ~ Sam Goldwyn