Linux: Clear contents of a file

Empty an in-use nohup.out file

cat /dev/null >nohup.out

 

If the file is not in use, the following works in bash

> foo.log

The command above empties out the file foo.log

If sudo is needed, truncate can be used as well

sudo truncate -s 0 foo.log

-s is the size option. 0 in this example sets the size to 0 bytes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s