Clear a file in Linux using :> operator

:> operator can be used to clear the contents of a file

$ cat file.txt

This file has some content. Let's use :> to clear the file

Let’s clear the file contents

$ :> file.txt

Let’s confirm this

$ stat file.txt
File: `file.txt'
 Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 801h/2049d    Inode: 1004        Links: 1
...

You can see more options to clear a file in Linux.

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