Skip to content
All 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.