emptying a file and keeping its ownership

Jonathan I. Kamens jik at athena.mit.edu
Tue Jan 1 08:40:30 AEST 1991


  Several people have suggested using

    > $FILE

to truncate a file while retaining its old permissions.  This will work under
sh or ksh or bash or other shells that allow null commands for redirection. 
Unfortunately, csh and tcsh do not allow such null commands :-(.  Therefore,
I'd like to point out another way to do this that works on most platforms I've
seen.

  From the man page for cp(1):

    DESCRIPTION
         File1 is copied onto file2.  By default, the mode and owner
         of file2 are preserved if it already existed; otherwise the
         mode of the source file modified by the current umask(2) is
         used.

Therefore, you can use

    cp /dev/null $FILE

to truncate a file and save its current permissions.

  I hope this helps.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.xenix.sco mailing list