Wednesday 18 November 2009

Bash file truncation

Today I wanted to truncate a file from bash and discovered that using the dummy placeholder : worked a treat:

:>example-file-to-truncate.txt

..I've been using bash for years and completely overlooked this gem - I should have devoted more effort into reading the POSIX 1003.2 standard or the bash manual a long while ago...

2 comments:

  1. Doesn't the following command achieve the same result?

    >example-file-to-truncate.txt

    ReplyDelete
  2. @MrM, you're right, you win the optimal solution award!

    ReplyDelete