February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  

Categories

February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  

Truncate a File to Zero byte in Linux

Sometimes you need to truncate/empty a file to zero byte length. For example, you have a big file that contains various logs and the size is too big to open it easily. Of course, you can remove this file and touch it again. But this way you will have to play with permissions and file ownership. There is a simple command that will truncate the file to zero length without affecting any permissions.

# > filename

If the file already exists, it will be truncated to zero bytes, else this command will create an empty file. This is great for truncating big log files, eg. Apache error logs.

> filename

eg

> nohup.out

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>