cat /dev/null > file.txt is a useless use of cat.
Basically cat /dev/null simply results in cat outputting nothing. Yes it works, but it's frowned upon by many because it results in invoking an external process that is not necessary.
It's one of those things that is common simply because it's common.
Using just > file.txt will work on most shells, but it's not completely portable. If you want completely portable, the following are good alternatives:
true > file.txt : > file.txt Both : and true output no data, and are shell builtins (whereas cat is an external utility), thus they are lighter and more 'proper'.
Update:
As tylerl mentioned in his comment, there is also the >| file.txt syntax.
Most shells have a setting which will prevent them from truncating aan existing file via >. You must use >| instead. This is to prevent human error when you really meant to append with >>. I think ksh has this on by default (but it's been years, so I'm not certain). However bash and other shells also support this, it's just off by default. With bash youYou can turn the behavior on with set -o noclobber.
Anyway, with this feature, you have to use >|C to truncate an existing file.
So fromwith this, I think the simplest, most proper, and portable method of truncating a file would be:
:>| file.txt