The shell redirection operator > allows you to create a new empty file:
$ > path/to/file
The same command can be used to empty an existing file (use with caution).
$ touch path/to/file
Also works, but won't empty an existing file. May be safer to not accidently empty an existing file.
@kornnflake touch also updates the accessed/modified date/time for existing files. You can even add the option --no-create to it so it only touches files that already exist, not creating any new files.
(just as a side note)
Thanks for your comments. I know about touch and the dangers of > file. But the latter is faster to type and less people might know that redirections can be used this way. Perhaps a better title would have been "Easiest way to create or empty a file in Shell".
FYI, I've updated the protip (title and contents) in response to your comments. Thanks again.
this is great thanks bro!
I just use
as well but will definitely start to use this a lot.