Truncating text files
There are several ways to truncate a text file using bash:
: > 'FILE'
From StackOverflow: : is a no-op in bash, so this essentially just opens the file for writing (which of course truncates the file) and then immediately closes it.
> 'FILE'
From StackOverflow: A simple redirection all by itself will clear the file
echo -n "" > 'FILE'
From Tecmint.com: Here, you can use an echo command with an empty string and redirect it to the file… You should keep in mind that an empty string is not the same as null… To send a null output to the file, use the flag -n which tells echo to not output the trailing newline that leads to the empty line produced in [a version without the -n flag set]
truncate -s 0 'FILE'
From Unix.StackExchange: As for efficient, the most efficient would be truncate -s 0 filename; see here: http://linux.die.net/man/1/truncate.