Shell - Always Be Conscious of Redirecting to an Existing File

The basic principle is to avoid output redirection’s default behavior to overwrite an existing file.

An existing file might be a link pointing to some other files, either hard or symbolic. You need to be absolutely sure whether it is a link or whether there are links pointing to it.

Overriding a “link” alters the actual data storage and all the links linking to this data storage will be affected, thus comes with potenially unwanted behaviors.

There is no such a mechanism to inform those links the change in data stroage.

Thereby, the best practice is to prevent overriding by default. The noclobber option prevents you from overwriting existing files with the > operator.

1
set -o noclobber