views:

122

answers:

1

I have a file called error.log on my server that I need to frequently truncate. I have rw permissions for the file. Opening the file in vi > deleting all content > saving works (obviously). But when I try the below

cat /dev/null > error.log

I get the message

File already exists.

Obviously there is some kind of configuration done on the server to prevent accidental overriding of files. Can anybody tell how do I "truncate" the file in a single command?

+6  A: 

You have the noclobber option set. The error looks like it's from csh, so you would do:

cat /dev/null >! file

If I'm wrong and you are using bash, you should do:

cat /dev/null >| file

in bash, you can also shorten that to:

>| file
R Samuel Klatchko
you are right about the shell being csh. How did you know that?
Wikidkaka
@Wikidkaka - based on the error message. csh on my system gives the similar `File exists` error while bash gives the very different `cannot overwrite existing file` error.
R Samuel Klatchko