:> 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.