Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I do this:

iptables -nvL > output.txt

output.txt ends up empty. If I do:

iptables -nvL >> output.txt

It works fine. Appending is working, but overwriting is not. Why?

share|improve this question
Are you running both as root and/or with sudo? What are the permissions on the directory and file? – OldTimer Aug 26 '11 at 19:27
I am running with root. – Chankey Pathak Aug 26 '11 at 19:29
Did you actually typo the name (ouput.txt), or is that just in the question? – Michael Mrozek Aug 26 '11 at 19:48
Yes I typed the correct name. – Chankey Pathak Aug 29 '11 at 16:09

You probably have the noclobber option enabled in your shell. This protects existing files from being overwritten by output redirection. To disable it, run set +o noclobber. Probably noclobber is set somewhere in your .bashrc, /etc/profile or other equivalent file.

See also man set or man bash for details.

share|improve this answer
That would result in the file getting zeroed out? That seems like a poor protection – Michael Mrozek Aug 28 '11 at 0:07
No, empty file is not the result of noclobber but of the fact that it has been created earlier and nothing was written to it. – rozcietrzewiacz Aug 28 '11 at 0:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.