Trim a file in csh

In bash, if you want to clear out a file, the easiest command may be “> file“:

  1. # cat test.txt
  2. Hello world!
  3. # > test.txt
  4. # cat test.txt
  5. #

But in csh, “> file“ will cause “Invalid null command.“ error:

  1. # cat test.txt
  2. Hello world!
  3. # > test.txt
  4. Invalid null command.

The solution is using “: > file“ command:

  1. # cat test.txt
  2. Hello world!
  3. # : > test.txt
  4. # cat test.txt
  5. #

Or employ “cat /dev/null > file“.

Reference:
What does a leading colon (:) mean in a script?.