Most answers here [1] [2] [3] use a single angle bracket to redirect to /dev/null, like this :
command > /dev/null
But appending to /dev/null works too :
command >> /dev/null
Except for the extra character, is there any reason not to do this ? Is either of these "nicer" to the underlying implementation of /dev/null ?
Edit:
The open(2) manpage says lseek is called before each write to a file in append mode:
O_APPEND
The file is opened in append mode. Before each write(2), the file offset is positioned at the end of the file, as if with lseek(2). The modification of the file offset and the write operation are performed as a single atomic step.
which makes me think there might be a tiny performance penalty for using >>
. But on the other hand truncating /dev/null seems like an undefined operation according to that document:
O_TRUNC
If the file already exists and is a regular file and the access mode allows writing (i.e., is O_RDWR or O_WRONLY) it will be truncated to length 0. If the file is a FIFO or terminal device file, the O_TRUNC flag is ignored. Otherwise, the effect of O_TRUNC is unspecified.
and the POSIX spec says >
shall truncate an existing file, but O_TRUNC is implementation-defined for device files and there's no word on how /dev/null should respond to being truncated.
So, is truncating /dev/null actually unspecified ? And do the lseek calls have any impact on write performance ?