23

cp is a massively popular Linux tool maintained by the coreutils team of the GNU foundation.

By default, files with the same name will be overwritten, if the user wants to change this behaviour they can add --no-clobber to their copy command:

   -n, --no-clobber
          do not overwrite an existing file (overrides a previous -i option)

Why not something like --no-overwrite?

  • 9
    The --no-clobber option is not specified in POSIX. It is specific of GNU implementation. – Paulo Tomé Mar 11 at 9:33
  • 3
    On the contrary, my opinion is that this is a relevant question. The purpose of the comment is to provide context to the question with relevant information. – Paulo Tomé Mar 11 at 9:53
  • 3
    Probably from the same source as the name noclobber in the shell's set builtin. But I don't know the timeline. – ilkkachu Mar 11 at 10:18
  • 3
    The -n, --noclobber option has been introduced in coreutils version 7.1 at the beginning of year 2009. 2009-01-14 Kamil Dudka <kdudka@redhat.com> – Paulo Tomé Mar 11 at 10:19
  • 3
    @TomasZubiri Welcome to the magical world of computer science etymology. I hope you come to love it as much as I do ! – leinaD_natipaC Mar 12 at 11:10
48

Clobber” in the context of data manipulation means destroying data by overwriting it. In the context of files in a Unix environment, the word was used at least as far back as the early 1980s, possibly earlier. Csh had set noclobber to configure > to refuse to overwrite an existing file (later set -o noclobber in ksh93 and other sh-style shells). When GNU coreutils added --no-clobber (in 2009), they used the same vocabulary that shells were using.

| improve this answer | |
  • 3
    The C shell had it in the 1980s, and at least one contemporary source bemoans it not being in the Korn shell of the time. (-: It is documented in the Andersons' The UNIX C shell field guide which was published by Prentice Hall in 1986 (ISBN 9780139374685) so probably had existed for a while before that. – JdeBP Mar 11 at 11:27
  • 4
    A quick check of the source in Diomidis Spinellis's archive reveals that noclobber was in the C shell from 2BSD in 1979, so one would have to find out where Bill Joy got the word from. – JdeBP Mar 11 at 11:45
  • 3
    Always wondered if 'clobber' was inspired by The Thing from The Fantastic Four, a la 'It's clobberin' time!' – siliconrockstar Mar 12 at 2:24
  • clobber (in this sense) goes back at least to 1941. Marvel coopted an existing word. I suppose it's possible that Bill Joy was a fan, or something, but it doesn't seem likely to be the sole reason for using the word. – Ross Presser Mar 13 at 17:20
26

Because this is actually a standard term. As explained in Wikipedia:

In software engineering, clobbering a file or computer memory is overwriting its contents. 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.

As mentioned on the same page, bash and other shells also use the term in their set -o noclobber or equivalent. This is just the standard term for this sort of thing, so it was a natural choice for the developers of cp.

| improve this answer | |
4

The term "clobber" is well-known in computing in general.

The --no-clobber/-n option for cp was only added on 2009-01-14 by Kamil Dudka <kdudka@redhat.com> (commit on github).

Specifically within the GNU project, it's also used in GCC to describe when a CPU instruction or inline asm statement destroys the contents of a register. So it's not a random choice English word, and it's not unlikely that people working on GNU projects written in C would be at least familiar in passing with usage of the term from GCC docs, or from other GNU project developers using it:

  • (clobber x) in GCC-internals machine description files that teach GCC what each instruction in an ISA does. (Similar constraints to inline-asm)
  • GNU C Extended Asm inline asm() statements have a "clobber" section to tell the compiler which registers the inline asm template steps on. Like this useless nonsensical x86 example:
    asm("xor %eax,%eax; mfence" ::: "eax", "memory", "cc");. e.g. an SO Q&A asking about a function-calling convention in those terms.
  • GCC docs for -fcall-used-reg describe it as telling the compiler that a given register is "clobbered" by function calls (i.e. tweaks the calling convention). As opposed to -fcall-saved-reg or -ffixed-reg.
  • GCC -Wclobbered warning - "Warn for variables that might be changed by longjmp or vfork." (IDK if this existed in 2009, but it demonstrates that this word gets used to describe this sort of thing in various contexts including option names in other programs).

The author of the coreutils commit that added --no-clobber, Kamil Dudka, is definitely familiar with GCC internals: he (later?) wrote a GCC plugin for formal verification of C programs.

I don't know whether GCC internals influenced his choice of name, or if that came from existing shell options like set noclobber, or both.

Fun fact: original authors of GNU cp include Torjorn Granlund, principal author of the gmplib project (GNU Multi-Precision), and who helped invent/implement GCC's multiplicative-inverse optimization for division by a compile-time constant (1994 paper, Stack Overflow Q&A).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.