[Cialug] who wants to play "name that command"
Tad Anhalt
tja at netins.net
Mon Jun 27 20:03:47 CDT 2005
Barry Von Ahsen wrote:
> I seem to recall that there was a command to delete the contents of a
> file, but leave the file and attributes the same. It's not strip(1),
> that's for object files, but maybe that's what I'm thinking of
>
> dc thought zero, but I can't find that one.
>
> yes, I can always #rm file; touch file, but I thought there was a single
> command
"rm file; touch file" doesn't leave the attributes the same (they'll
end up however your umask is set). Worse yet, if the file you're
attempting to truncate has a process with an open file descriptor to it
(like if it's a log file for a daemon process, etc.) the results aren't
likely to be what you want.
Dave Weis already mentioned "cat /dev/null > file" which will work as
expected. The shorthand version "> file" works as well.
HTH,
Tad Anhalt
More information about the Cialug
mailing list