For the general question about creating files, see: Why isn't there any shell command to create files?
With both > file
and echo >> file
, the shell creates the file if it didn't already exist.
With > file
, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.
echo
, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, \n
):
% echo | od -c
0000000 \n
0000001
So with echo >> file
, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >>
(append) instead of >
(overwrite).
touch
creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch
doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch
.
Which you want to use depends on what effect you want.