Skip to content
Back to posts

Fast Ways to Empty a File on Linux

A quick reference to shell redirection and utilities that clear file contents without removing the file itself.

Fast ways to empty a file

Terminal window
echo "" > filename
echo /dev/null > filename
echo > filename
cat /dev/null > filename
: > filename # `:` is a placeholder and produces no output.
> filename

Originally published on SegmentFault.

Copyright notice

Unless otherwise stated, quietin owns the copyright in all articles. All rights reserved. Except as permitted by law or with prior written permission, reproduction or republication, in whole or in part, is prohibited. Permitted quotations must credit the author and link to the original article.