0

I am trying to truncate a file in Red Hat 4.8.5-11. I have zsh+prezto installed on my system. I am getting error: "zsh: file exists: {file_name}"

I am running following command:

echo -n > {file_name}

Same command is running just fine in bash. What could possibly be wrong?

Geek
  • 1,369
  • 1
  • 14
  • 25

1 Answers1

3

This is caused by the no-clobbering setting which protects you from accidently overwriting a file: http://zsh.sourceforge.net/Doc/Release/Options.html#index-file-clobbering_002c-allowing

You can either force it using the pipe character:

echo -n >| {file_name}

Or you can disable this behaviour by enabling clobbering:

setopt clobber
Wolph
  • 78,177
  • 11
  • 137
  • 148