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

Re: truncating files


Carl Mummert <mummert@cs.wcu.edu> writes:
> Is there already a (standard) utility on a linux box to truncate a
> file to 0 bytes?  [Besides echo -n "" > foo, which is 1) too long for
> my lazy fingers and 2) won't take multiple filenames ]
> Since I couldn't find one, I wrote a little C program to do it, but I
> am still interested in whether there is already one on the system.

Other users have suggested the use of "> foo", a "null command", but
that does not work in tcsh, my preferred shell.  Note that "echo > z"
does not, as you might expect it to, add a blank line (at least under
tcsh).  So you can save 5 characters from your example that way.

However the way I do this is by doing "cp /dev/null foo"... I don't
remember why but this is supposedly a better way of doing it.  I think
it preserves the file permissions more accurately?  I am not sure.
I picked that up years ago but have since forgotten the reason...


- --Bill.

- -- 
William R Ward          Bay View Consulting   http://www.bayview.com/~hermit/
hermit@bayview.com     1803 Mission St. #339        voicemail +1 408/479-4072
wrw@bayview.com       Santa Cruz CA 95060 USA           pager +1 408/458-8862

Version: 2.6.2
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface


TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .

Reply to: