Take the 2-minute tour ×
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.

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
3  
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
add comment

1 Answer

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
1  
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
add comment

Your Answer

 
discard

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.