How to empty the contents of a file in Linux

subject: Shell · date: 2017-12-11

  • To empty filename, use >:

    $ > filename
    
  • Use cp:

    $ cp /dev/null filename
    
  • Use truncate:

    $ truncate -s 0 filename
    

read more

share this article