In computing, clobbering is the act of overwriting a resource such as a file, processor register or a region of memory, such that its content is lost. Generally, the term is used in the context of unintentional loss of information, but it can be used for intentional overwriting as well. [1] The Jargon File defines clobbering as
To overwrite, usually unintentionally: "I walked off the end of the array and clobbered the stack." Compare mung , scribble, trash, and smash the stack . [2]
The term originated in pottery, where clobbering is a traditional term for the deceptive and fraudulent later addition of decoration to an originally plain piece. This was especially done to Chinese porcelain, but also European wares. [3]
In many shells, the >
file redirection operator clobbers if the output path refers to an existing file. This can be prevented in bash and ksh via the command set -o noclobber
and in csh and tcsh via set noclobber
. Subsequently, attempting to clobber via redirection fails with an error message. [4] For example:
$echo"Hello, world">file.txt $catfile.txt Hello,world $echo"This will overwrite the first greeting.">file.txt $catfile.txt Thiswilloverwritethefirstgreeting. $set-onoclobber $echo"Can we overwrite it again?">file.txt -bash:file.txt:cannotoverwriteexistingfile $echo"But we can use the >| operator to ignore the noclobber.">|file.txt $catfile.txt# Successfully overwrote the contents of file.txt using the >| operator Butwecanusethe>|operatortoignorethenoclobber. $set+onoclobber# Changes setting back
The default behavior of the mv
and cp
commands is to clobber an existing destination file. This behavior may be overridden via the -i
option which results in prompting the user to confirm clobbering a file. Alternatively, the -n
option selects to skip operations that would clobber.
A commonly used make
target, named clobber, performs a complete cleanup of files and directories produced via previous invocations of the command for a particular makefile. [5] It is a more thorough cleanup operation than clean and is commonly used to uninstall software. Some make-related commands invoke make clobber
during their execution. They check the CLOBBER environment variable. If it is set to OFF then clobbering is not done. [6]
In assembler programming (including GCC inline assembly [7] ) a clobbered register denotes a register whose value may be overwritten in the course of executing an instruction.
The term "clobbering" is used in several different ways in computing, with the meaning usually clear from the context. In one sense, it refers to overwriting existing files or memory entries. It can also be used to discuss overwhelming computers such as servers with requests, causing a downgrade in performance. This second usage of the word reflects the common usage of "clobber" as a word to describe taking a beating.