April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

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>