‹ BackHN Continuity

Thread

cp: -r or -R?

125 points · 107 comments · zdw

Loading the complete thread in the background. This saved snapshot is available now. Refresh

  1. bsoqk · · focus · HN ↗
    It's "ditto", not "dito"
    1. Waterluvian · · focus · HN ↗
      As in the Pokémon, not the Philippines telecom company.
      1. Yaqub_W · · focus · HN ↗
        Much easier to press a key twice than to hunt for é for most people. I get your point though
        1. Waterluvian · · focus · HN ↗
          Apparently Pokémon is in my phone’s word book.
        2. greatgib · · focus · HN ↗
          I never noticed but indeed in France the official name is "Pokémon" and not "Pokemon". So that the pronunciation in French is correct.

          Is it the case in another country to have a localized name for that?

          1. amenghra · · focus · HN ↗
            Pokémon is the trademark (see e.g. <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pok%C3%A9mon" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pok%C3%A9mon). Pokemon is common spelling in countries where keyboards don&#x27;t have é and&#x2F;or where people aren&#x27;t used to inputting é.

            It is common for brands to localize their names. E.g. Axe (the deodorant) in some countries is branded as Lynx.

          2. 317070 · · focus · HN ↗
            Pokémon has an accent in all languages: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pok%C3%A9mon" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pok%C3%A9mon
          3. jolmg · · focus · HN ↗
            In Spanish, it&#x27;s there but it&#x27;s a bit wrong&#x2F;redundant. The phonic&#x2F;prosodic accent would&#x27;ve been on the &quot;e&quot; regardless because of the &quot;n&quot; ending, so it&#x27;s a bit wrong to add it graphically as if it would&#x27;ve been elsewhere.

            Is it the case that it would&#x27;ve been pronounced differently without the written accent in French?

            1. Dylan16807 · · focus · HN ↗
              English doesn&#x27;t really use acute accents for stress though. Especially on an e it&#x27;s usually there to change the vowel sound.
        3. swiftcoder · · focus · HN ↗
          Lucky that the other modern OSes have all decided to make this as trivial as it is on MacOS &#x2F;sarcasm
      2. [deleted] · · focus · HN ↗

        [deleted]

    2. NaiveBayesian · · focus · HN ↗
      Huh, TIL. In German, &quot;dito&quot; is the correct spelling, so I always figured it would be the same in English as well.
      1. andrewshadura · · focus · HN ↗
        In Slovak, it’s detto :)
  2. mqus · · focus · HN ↗
    would you be safe in using --recursive always? (e.g. shell scripts)
    1. olowe · · focus · HN ↗
      There are implementations of cp out in the wild that do not recognise the —-recursive flag. OpenBSD was mentioned in the article and there’s also busybox cp <a href="https:&#x2F;&#x2F;busybox.net&#x2F;downloads&#x2F;BusyBox.html" rel="nofollow">https:&#x2F;&#x2F;busybox.net&#x2F;downloads&#x2F;BusyBox.html
    2. hnfong · · focus · HN ↗
      Double dash long options are basically a GNU extension. BSD utilities generally don&#x27;t support them. Apparently macOS does not either (since it&#x27;s based off of FreeBSD)
      1. JdeBP · · focus · HN ↗
        macOS was based off NeXTSTEP, not FreeBSD.

        And the received wisdom about long options in the BSDs is a quarter of a century out of date. When the BSDs gained a getopt_long() in their C libraries thanks to Klausner and Baron, long options quietly started appearing. This process has been gradually and quietly on-going for the whole of the 21st century.

        1. throw0101a · · focus · HN ↗
          &gt; macOS was based off NextBSD, not FreeBSD.

          &quot;NextBSD&quot; was first released in 2015:

          * <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;NextBSD" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;NextBSD

          Over a decade after macOS&#x2F;Mac OS X was initially released:

          &gt; macOS (previously OS X and originally Mac OS X) is a proprietary Unix[7][8] operating system, derived from OPENSTEP for Mach and FreeBSD, which has been marketed and developed by Apple since 2001.

          * <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;MacOS" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;MacOS

          &gt; Darwin is the core Unix-like operating system of macOS, iOS, watchOS, tvOS, iPadOS, audioOS, visionOS, and bridgeOS. It previously existed as an independent open-source operating system, first released by Apple in 2000. It is composed of code derived from NeXTSTEP, FreeBSD[3] and other BSD operating systems,[7] Mach, and […]

          * <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Darwin_(operating_system)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Darwin_(operating_system)

          I remember reading release notes for FreeBSD in the &#x27;00s and seeing the exact same lines in the release notes for earlier versions of OS X.

          1. JdeBP · · focus · HN ↗
            Bah! Thought NeXTSTEP. Typed NextBSD. Fixed. I&#x27;ve been typing lots of names ending in &#x27;BSD&#x27; today. (-:
            1. hnfong · · focus · HN ↗
              I posted my original comment based off my pre-existing knowledge, but here&#x27;s a more in-depth explanation of the macOS and FreeBSD situation (which aligns with my understanding):

              <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;freebsd&#x2F;comments&#x2F;1g07sdm&#x2F;comment&#x2F;lr6rizo&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;freebsd&#x2F;comments&#x2F;1g07sdm&#x2F;comment&#x2F;lr...

              Essentially, macOS was indeed based on NeXTSTEP originally, but over the years they copied quite a bit of BSD code over (mostly FreeBSD I think). I don&#x27;t think the Unixy parts of the original NeXTSTEP survives much in modern macOS.

          2. alwillis · · focus · HN ↗
            &gt; Darwin is the core Unix-like operating system of macOS

            macOS isn&#x27;t &quot;Unix-like&quot;; it&#x27;s an Open Group certified UNIX™ [1].

            [1]: <a href="https:&#x2F;&#x2F;www.opengroup.org&#x2F;openbrand&#x2F;register&#x2F;brand3725.htm" rel="nofollow">https:&#x2F;&#x2F;www.opengroup.org&#x2F;openbrand&#x2F;register&#x2F;brand3725.htm

        2. toast0 · · focus · HN ↗
          Much of the macos Unix userland is from FreeBSD as are some parts of the kernel, such as the ip stack. Check the man pages for cp and friends in mac and I believe they still reference FreeBSD.

          &gt; And the received wisdom about long options in the BSDs is a quarter of a century out of date.

          Incidentally, so is much of the FreeBSD code. Many things were taken once, never updated from upstream again. I think a lot of the userland did get an update somewhere around 2014... all of a sudden, cal would highlight the current date, years after that happened upstream. But the IP stack hasn&#x27;t gotten any updates from upstream AFAIK, probably because Apple customized it and it&#x27;s too much work to merge in improvements that probably won&#x27;t be noticed on client systems (things like syncookies).

    3. dotancohen · · focus · HN ↗
      I believe that -R is the safe option.
  3. here_to_learn · · focus · HN ↗

    [dead]

  4. drhagen · · focus · HN ↗
    It always seemed like the recursive flag of cp was an implementation detail leaking into the UI. Like, I get that copying a file requires creating more than one inode, but...so? Eventually, graphical OSes agree with me—copy&#x2F;paste works the same on folders as it does on files.
    1. dotancohen · · focus · HN ↗
      Thirteen years ago I asked the same question:

      <a href="https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;82485&#x2F;when-wouldnt-one-want-cp-to-be-recursive" rel="nofollow">https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;82485&#x2F;when-wouldnt-...

      It seems that recursive by default would have been much more intuitive.

      1. JdeBP · · focus · HN ↗
        It&#x27;s rather sad that none of the answers were that the cp command simply did not gain a recursive option until the 1980s, well into the 1980s if you were on one side of the Unix wars.

        Yes, seriously. When you read about the supposed evils of cat -v from the Unix nostalgia people, remember that it was the same people who gave cat its -v option who also gave cp its -r option, in 4.2BSD.

        It took over half a decade to percolate out of the BSD world, too. AT&amp;T Unix System 5 did not have an -r option to cp. Here&#x27;s Brandon S. Allbery explaining in 1987 how one copies directories on AT&amp;T Unix System 5 Releases 2&#x2F;3 by combining find and cpio -p:

        * <a href="https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;comp.unix.questions&#x2F;c&#x2F;XiumTgkcYRE&#x2F;m&#x2F;kJwkU5SlOasJ" rel="nofollow">https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;comp.unix.questions&#x2F;c&#x2F;XiumTgkcYR...

        Originally we read directories as raw byte streams and liked it, you know. (-:

        1. Joker_vD · · focus · HN ↗
          &gt; When you read about the supposed evils of cat -v from the Unix nostalgia people, remember that it was the same people who gave cat its -v option who also gave cp its -r option, in 4.2BSD.

          Then the people who complained about cat -v went ahead and made better Unix, called Plan 9, in which moving (as opposed to merely renaming) a directory is impossible: instead, you&#x27;re supposed to do mkdir &amp;&amp; dircp &amp;&amp; rm -r. Which is quite a choice, if I say so myself: there is simply no low-level primitive (syscall or 9p message) for moving files across directories, even on the same file server. Their version of mv can move files across the directories, but it&#x27;s still done with internal equivalent of cp+rm.

        2. ButlerianJihad · · focus · HN ↗
          You know, when I came into Unix in the 1990s we still didn&#x27;t care about recursive copy, because all admins learned the standard idiom to copy over a hierarchy:

            tar cf - . | ( cd &#x2F;new&#x2F;path; tar xpf - )
          
          or thereabouts, because at the time, `tar` was more than capable of doing all the filesystem tricks that `cp` was clumsy with, and we understood this idiom well. You could also `dump` an entire block device.

          I believe that my motivation was that the Unix wars were still raging hotly; as a sysadmin I needed portable skills and I wasn&#x27;t tied or certified to one vendor&#x27;s Unix, and therefore I sought out idioms that worked on SunOS, HP&#x2F;UX, AIX, BSD, you name it. &quot;cp -r&quot; didn&#x27;t enjoy that stable support at the time.

          1. JdeBP · · focus · HN ↗
            I don&#x27;t care all that much even today. (-:

            I use pax -r -w most of the time.

    2. alwillis · · focus · HN ↗
      ditto is an option on macOS for copying files and directories [1].

      [1]: <a href="https:&#x2F;&#x2F;keith.github.io&#x2F;xcode-man-pages&#x2F;ditto.1.html" rel="nofollow">https:&#x2F;&#x2F;keith.github.io&#x2F;xcode-man-pages&#x2F;ditto.1.html

  5. 5555watch · · focus · HN ↗
    On a somewhat related note, I really hate that in scp -r and -R mean entirely different things.
    1. aulin · · focus · HN ↗
      How about port that is lowercase in ssh and uppercase in scp?
      1. wanick · · focus · HN ↗
        scp took -p from rcp&#x2F;cp, where it already meant preserve times. So port got -P.
    2. pluc · · focus · HN ↗
      The worst is when things behave different when you give them `~&#x2F;somedir` vs `~&#x2F;somedir&#x2F;`. I think it&#x27;s rsync that does that
      1. amelius · · focus · HN ↗
        Yes, into versus onto. Luckily we have AI to write our command lines.
      2. IshKebab · · focus · HN ↗
        And `cp`.
        1. brewmarche · · focus · HN ↗
          I remember that macOS&#x2F;FreeBSD’s cp -R behaves differently depending on the trailing slash (it’s pointed out in the man page). But when I compared with GNU coreutils and busybox they did not, so it’s something to look out for.
      3. mjmas · · focus · HN ↗
        rsync, or at least the version I had would behave differently for &#x27;rsync a b&#x27; vs &#x27;rsync a&#x2F; b&#x2F;&#x27;, even though I added the slash for both sides.
      4. GrantMoyer · · focus · HN ↗
        I really like this feature of rsync (trailing &quot;&#x2F;&quot; means copy the directory contents to the dest, no trailing &quot;&#x2F;&quot; means copy the directory itself). Other tools, like cp, don&#x27;t have any way at all to say copy the directory contents to the dest, and for those tools the result depends on whether the destination already exists and is a directory (you might end up with a duplicate nested diretory). Rsync produces the se result whether the destination already exists or not.
        1. 0xpgm · · focus · HN ↗
          Why not let the shell do the expansion of `somedir&#x2F;*` to refer to the content of the directory instead?
  6. mkl · · focus · HN ↗
    -a

    Not sure why you wouldn&#x27;t want to preserve timestamps, links, etc. by default.

    1. JdeBP · · focus · HN ↗
      This is rather missing the point. The headlined article isn&#x27;t really about how to achieve a goal, but about the weird history and evolution of a tool that leads us to the rather odd situation that we are in today. And it&#x27;s far from being the only tool that has a weird history, that looks rather nutty if one looks at it from the point of view of a novice having to learn this stuff.

      It&#x27;s also not even completely covering the weird case of -r and -R for the cp command. On HP-UX, for example, the twain were different, but not in the way that they were in old GNU Core Utilities. That would be too easy. (-:

      The AIX manual for cp explains its difference between -r and -R:

      * <a href="https:&#x2F;&#x2F;ibm.com&#x2F;docs&#x2F;en&#x2F;aix&#x2F;7.1.0?topic=c-cp-command" rel="nofollow">https:&#x2F;&#x2F;ibm.com&#x2F;docs&#x2F;en&#x2F;aix&#x2F;7.1.0?topic=c-cp-command

      Illumos also treats the two differently, but in a subtly different way:

      * <a href="https:&#x2F;&#x2F;illumos.org&#x2F;man&#x2F;1&#x2F;cp" rel="nofollow">https:&#x2F;&#x2F;illumos.org&#x2F;man&#x2F;1&#x2F;cp

      1. Joker_vD · · focus · HN ↗
        That&#x27;s why, just as fork(2) is a primitive for the process creation, copy(2) should&#x27;ve been the primitive for the file creation — creates an exact copy of the file under a new name, but with the exact same content and all of the metadata (except for the name, obviously), including its kind, permissions, timestamps, etc. And no, it wouldn&#x27;t be prohibitively expensive because all filesystems can quite easily support CoW; after all, most of the created files will be truncate(2)d almost immediately, so there is no point to eagerly duplicate the file contents.

        The &quot;metadata is atomically copied&quot; part would support very nicely the usual text editor&#x27;s idiom of rename(2)ing a temporary file over the source after fully writing it out — you still need to accurately replicate the permissions and extended attributes. And just as shells are important enough programs to have fork(2) almost exactly suited for them, it would make sense to have copy(2), suited for the text editors.

        1. JdeBP · · focus · HN ↗
          When cp was invented, &#x27;most filesystems&#x27; did not have the first clue about copy on write.

          However, I should note that possibly the first company to invent what you describe was Microsoft.

          Novell Netware 386 had an NCOPY command which invoked a Netware extension to the DOS API that told the server to perform the entire copy on the server.

          But even earlier, OS&#x2F;2 1.x had a proper DosCopy() system call. Since it could be passed down to the installable filesystem drivers for intra-volume copies, something like the Netware client for OS&#x2F;2 could in theory turn it into the same protocol call that did server-side copies. There was a NET COPY command in LAN Manager (and LAN Server, if memory serves) that did the same optimization.

          * <a href="https:&#x2F;&#x2F;www.edm2.com&#x2F;index.php&#x2F;DosCopy_(OS&#x2F;2_1.x)" rel="nofollow">https:&#x2F;&#x2F;www.edm2.com&#x2F;index.php&#x2F;DosCopy_(OS&#x2F;2_1.x)

          * <a href="https:&#x2F;&#x2F;www.edm2.com&#x2F;index.php&#x2F;FS_COPY" rel="nofollow">https:&#x2F;&#x2F;www.edm2.com&#x2F;index.php&#x2F;FS_COPY

          1. Joker_vD · · focus · HN ↗
            &gt; When cp was invented, &#x27;most filesystems&#x27; did not have the first clue about copy on write.

            Eh, when fork was invented, most (virtual) memory systems did not have the first clue about copy-on-write either. And honestly, it&#x27;s really not that difficult to support — it&#x27;s essentially hard links, just with slightly different semantics.

            1. collinfunk · · focus · HN ↗
              In theory, I agree that it shouldn&#x27;t be tricky. However, in practice, it is a bit tricky since all the different implementations have different ways to perform reflinks.

              Linux has FICLONE [1], which I prefer because it operates on two file descriptors, allowing you to safely modify file metadata after the fact. macOS has clonefile, clonefileat, and fclonefileat [2]. Sadly, there is no way to operate on two file descriptors. The best you get is fclonefileat, which operates on a source file descriptor. Solaris has reflink and reflinkat, which operate on two paths, the latter relative to file descriptors [3]. In that case, one needs to be careful opening the destination to make changes to the metadata.

              GNU coreutils has support for reflinks on Linux and macOS. But I&#x27;ve been thinking about adding support for Solaris as of late [4]. Sadly, I don&#x27;t use it enough to test it as much as I would like.

              Hopefully, a few years down the line the interfaces converge, and it is as simple as hard linking.

              [1] <a href="https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man2&#x2F;FICLONE.2const.html" rel="nofollow">https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man2&#x2F;FICLONE.2const.html [2] <a href="https:&#x2F;&#x2F;www.manpagez.com&#x2F;man&#x2F;2&#x2F;clonefile&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.manpagez.com&#x2F;man&#x2F;2&#x2F;clonefile&#x2F; [3] <a href="https:&#x2F;&#x2F;docs.oracle.com&#x2F;cd&#x2F;E86824_01&#x2F;html&#x2F;E54766&#x2F;reflinkat-3c.html" rel="nofollow">https:&#x2F;&#x2F;docs.oracle.com&#x2F;cd&#x2F;E86824_01&#x2F;html&#x2F;E54766&#x2F;reflinkat-3... [4] <a href="https:&#x2F;&#x2F;lists.gnu.org&#x2F;archive&#x2F;html&#x2F;coreutils&#x2F;2026-09&#x2F;msg00121.html" rel="nofollow">https:&#x2F;&#x2F;lists.gnu.org&#x2F;archive&#x2F;html&#x2F;coreutils&#x2F;2026-09&#x2F;msg0012...

    2. emmelaich · · focus · HN ↗
      old cp didn&#x27;t have `-a`

      Anyway, just use rsync.

      1. dspillett · · focus · HN ↗
        &gt; just use rsync

        You still need to specify --archive (or --times for the individual option) to preserve mtime in the target copy.

  7. pasc1878 · · focus · HN ↗
    Use rsync instead
    1. trucks-refinish · · focus · HN ↗
      rsync unfortunately doesn&#x27;t do relinking at all, so I can&#x27;t use it as a generic replacement for cp.
      1. groestl · · focus · HN ↗
        Relinking?
        1. rincebrain · · focus · HN ↗
          I assume they typoed reflinking, a way of doing CoW-based copying of file contents.
          1. groestl · · focus · HN ↗
            I was under the impression it could do that, I think I build a snapshotting mechanism using this.
            1. Flimm · · focus · HN ↗
              rsync does not have the ability to copy a file using the filesystem&#x27;s copy-on-write feature. This is unlike cp, which has the --reflink flag. Here&#x27;s the bug report on GitHub which the developers closed as &quot;won&#x27;t fix for now&quot;:

              <a href="https:&#x2F;&#x2F;github.com&#x2F;RsyncProject&#x2F;rsync&#x2F;issues&#x2F;119#issuecomment-3769076742" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;RsyncProject&#x2F;rsync&#x2F;issues&#x2F;119#issuecommen...

          2. trucks-refinish · · focus · HN ↗
            yes thank you!
    2. 5555watch · · focus · HN ↗
      In my minimal attempts to use rsync, I always find examples where they always use a ton of flags alongside the locations. I&#x27;m not gonna learn those flags if cp can do it intuitively and with minimal extra commands. Maybe it&#x27;s just me.
      1. CoastalCoder · · focus · HN ↗
        Not just you.

        Also, I always have this vague fear that I&#x27;ll rsync in the wrong direction, or accidentally blow away unrelated files in rsync&#x27;s efforts to fully synchronize two directories (can&#x27;t remember if this is a valid concern).

        I&#x27;m sure these concerns would go away if I used it regularly, but I just don&#x27;t. ‘cp&#x27; or ’scp’ almost always meet my needs.

        1. toast0 · · focus · HN ↗
          &gt; Also, I always have this vague fear that I&#x27;ll rsync in the wrong direction

          It&#x27;s the same direction as cp&#x2F;scp ... You could easily do it wrong, but you must be afraid to do anything other than maybe cat &lt; source &gt; dest because that&#x27;s clear?

          &gt; or accidentally blow away unrelated files in rsync&#x27;s efforts to fully synchronize two directories (can&#x27;t remember if this is a valid concern).

          I think you need --delete for this. As I recall, it&#x27;s sometimes more tricky to get it to delete the files you wanted it to delete and you&#x27;re more likely to end up with extra files than not.

      2. groestl · · focus · HN ↗
        Do it once, make it your muscle memory - it&#x27;s really hard for me to learn things by heart, but even I could do it :), and then you can forget about scp as well
  8. bariumbitmap · · focus · HN ↗
    This blog post is odd because it keeps on hinting about a difference between `-r&#x27; and `-R&#x27; and links to the source code but never actually says what it is. I&#x27;ll quote the OpenBSD manual that the post mentions but does not link to for some reason:

    &gt; Historic versions of the cp utility had an -r option. This implementation supports that option; however, its use is strongly discouraged, as it does not correctly copy special files, symbolic links or FIFOs.

    <a href="https:&#x2F;&#x2F;man.openbsd.org&#x2F;cp" rel="nofollow">https:&#x2F;&#x2F;man.openbsd.org&#x2F;cp

    1. embedding-shape · · focus · HN ↗
      &gt; links to the source code but never actually says what it is.

      The snippet of code makes it very clear what the difference is, no?

      flag_copy_as_regular = 1 VS flag_copy_as_regular = 0, where regular would be a &quot;regular&quot; and not &quot;special&quot; file.

      1. maxlin · · focus · HN ↗
        Nope. That variable name could mean anything
      2. Modified3019 · · focus · HN ↗
        I have no idea what that means, or what the consequences would be for choosing one or the other.
      3. rezonant · · focus · HN ↗
        Only clear to those with a heavy UNIX background-- I understood and correctly interpreted it on first read, but the concept of a &quot;regular file&quot; is a bit in the wonk territory for most users, though the implication on symbolic links is a very practical one that surely lead to the removal (in the implementations where it was removed) of this option, since its very surprising that copying a directory heirarchy would cause symbolic links to become copies of what they linked to, instead of remaining symbolic links in the resulting directory.
      4. wodenokoto · · focus · HN ↗
        That’s for gnu implementation. For the BSD implementation author just links to the source code.
    2. rakel_rakel · · focus · HN ↗
      You can see it in the code, lstat vs stat and copy_special, copy_fifo vs copy_file. They&#x27;re all in utils.c.

      from the lstat man page:

           The lstat() function is identical to stat() except when the named file is
           a symbolic link, in which case lstat() returns information about the link
           itself, not the file the link references.
      
      symbolic link example:

          $ tree test1
          test1
          |-- file.txt
          `-- link.txt -&gt; ..&#x2F;link.txt
      
          0 directory, 2 files
      
          $ cp -r test1 test2
          $ tree test2
          test2
          |-- file.txt
          `-- link.txt
      
          0 directory, 2 files
      
          $ cp -R test1 test3
          $ tree test3
          test3
          |-- file.txt
          `-- link.txt -&gt; ..&#x2F;link.txt
      
          0 directory, 2 files
      
      For posterity, -R with added -L

          $ cp -RL test1 test4
          $ tree test4&#x2F;
          test4&#x2F;
          |-- file.txt
          `-- link.txt
      
          0 directory, 2 files
  9. bdavbdav · · focus · HN ↗
    This always get me. I instinctively -r, until chown which of course doesn’t take it.
    1. jwrallie · · focus · HN ↗
      The worst is that I can never remember if it’s chown or chmod that is the odd one.
      1. bdavbdav · · focus · HN ↗
        Exactly - and I always get it wrong first time.
  10. throwaway2046 · · focus · HN ↗
    I&#x27;m more inclined to use the uppercase -R as it&#x27;s standardized by POSIX and will generally behave the same on any POSIX compliant system.
    1. WhyNotHugo · · focus · HN ↗
      It&#x27;s also the only option shown in the -h output and in man pages for some versions of cp.

      I didn&#x27;t even know -r was a thing until today.

  11. spijdar · · focus · HN ↗
    &gt; nobody™ still runs coreutils from 24 years ago.

      Sprite 2.077 pc386
      
              Welcome to Sprite
      
      root@cherimoya [1] # cp --version
      GNU fileutils 3.9
      root@cherimoya [2] # cp --help | grep recurs
        -r                           copy recursively, non-directories as files
        -R, --recursive              copy directories recursively
      root@cherimoya [3] #
    
    I&#x27;ll take the honorary title of nobody ;-)
    1. kijin · · focus · HN ↗
      You should have run that command as the `nobody` user.
      1. tosti · · focus · HN ↗
        But nobody doesn&#x27;t have a valid shell.
        1. kijin · · focus · HN ↗
          Nothing you can&#x27;t fix if you have root. :)
          1. laxd · · focus · HN ↗
            Use toor for good measure.
    2. collinfunk · · focus · HN ↗
      Hey, I perfectly understand if not. But do you have the sources that were used to build those binaries?

      The oldest version on the GNU ftp server is fileutils-3.13 [1]. I vaguely remember having some links to older versions, probably somewhere in my archived mail. But I don&#x27;t remember if it was fileutils-3.9 or earlier.

      I co-maintain GNU coreutils, so I am interested in reading them. If you have them, you can email me privately or on the public mailing list. Both are listed on the homepage [2].

      [1] <a href="https:&#x2F;&#x2F;ftp.gnu.org&#x2F;old-gnu&#x2F;fileutils&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ftp.gnu.org&#x2F;old-gnu&#x2F;fileutils&#x2F; [2] <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;coreutils&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;coreutils&#x2F;

      1. tosti · · focus · HN ↗
        You can find ancient distros on archive.org and some of those have src.rpm&#x27;s Slackware also had a source dvd with iirc regular tarballs.
        1. collinfunk · · focus · HN ↗
          Interesting, thanks for the pointers!
          1. tosti · · focus · HN ↗
            Also, Debian has archives of old releases. You might want to try your luck there.
            1. eichin · · focus · HN ↗

              [dead]

      2. Sophira · · focus · HN ↗
        When you get to packages that are old enough, DiscMaster[0] is helpful for this since these packages were often on magazine cover CD-ROMs! There are several files matching &quot;fileutils-3.9.tar.gz&quot;[1]; the two variants seem to be the original GNU release (182.9KiB, the one you&#x27;re looking for), and what looks like the result of a &quot;make install&quot; (57.4KiB).

        The original GNU release of fileutils-3.6 is there too (but be careful; one of the two files appears to include Makefiles from a .&#x2F;configure run, while the other doesn&#x27;t), though 3.7 and 3.8 don&#x27;t appear to be. You&#x27;ll need to sift through to find what you need in some cases, but it&#x27;s an incredibly valuable research tool.

        Note: To download a file, you&#x27;ll need to click on the filename, and then click the small arrow at the top that looks like a red arrow pointing down to a white box with red&#x2F;green lights. (Which I assume is their representation of a desktop computer.)

        [0] <a href="https:&#x2F;&#x2F;discmaster.textfiles.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;discmaster.textfiles.com&#x2F;

        [1] <a href="https:&#x2F;&#x2F;discmaster.textfiles.com&#x2F;search?q=fileutils-3.9.tar.gz" rel="nofollow">https:&#x2F;&#x2F;discmaster.textfiles.com&#x2F;search?q=fileutils-3.9.tar....

  12. krn1p4n1c · · focus · HN ↗
    tar cf - . | tar xf - -C &lt;dest&gt;
    1. Rygian · · focus · HN ↗
      with a sandwiched `| pv |` for fun stats
      1. dspillett · · focus · HN ↗
        And `| ssh &lt;target&gt; ` for a remote copy.

        (or ssh &lt;target&gt; prepended rather than sandwiched, to copy from remote)

        1. Rygian · · focus · HN ↗
          At some point it starts very much looking like zfs send | pv | ssh &lt;target&gt; zfs receive
          1. krn1p4n1c · · focus · HN ↗
            Seriously. I do wish ZFS was everywhere.
        2. krn1p4n1c · · focus · HN ↗
          I usually sandwich zstd and base64 encode&#x2F;decode in with the ssh pipe. Used when I need root permissions to pull the remote dirs.
          1. dspillett · · focus · HN ↗
            You shouldn&#x27;t need to encode - piping over SSH is binary safe. Verifying with 100Mbyte of random data:

                user@host:&#x2F;tmp$ pv rnd.file | sha256sum
                 100MiB 0:00:00 [ 224MiB&#x2F;s] [=======================================================================================&gt;] 100%
                71d3392be59210c517ab889fca715a46dee54f6326a9d901db0addd351607cb6  -
                user@host:&#x2F;tmp$ pv rnd.file | ssh user@otherhost sha256sum
                 100MiB 0:00:04 [21.9MiB&#x2F;s] [=======================================================================================&gt;] 100%
                71d3392be59210c517ab889fca715a46dee54f6326a9d901db0addd351607cb6  -
                user@host:&#x2F;tmp$ pv rnd.file | zstd -z | ssh user@otherhost &quot;zstd -d | sha256sum&quot;
                 100MiB 0:00:07 [13.7MiB&#x2F;s] [=======================================================================================&gt;] 100%
                71d3392be59210c517ab889fca715a46dee54f6326a9d901db0addd351607cb6  -
            
            When using zstd (or anything else) make sure you don&#x27;t have something in your .sss&#x2F;config that would make ssh use a compression as you&#x27;ll waste a bit of CPU to send a little more data as a less efficient compression method is applied on top. Though TBH I think that unless I&#x27;m on a very slow link, if I&#x27;m sending something big enough to need compression it is probably in a pre-compressed or otherwise uncompressable format anyway (video, photos, …) so zstd does little, the one exception I can think of being if I&#x27;m throwing an unencrypted VM image from place to place.
    2. jhallenworld · · focus · HN ↗
      I never bothered to learn -C, instead I use:

          tar -cf - . | (cd &lt;dest&gt;;  tar -xf -)
      
      For doing something like duplicating root of a filesystem you may want --one-file-system.
  13. xrd · · focus · HN ↗
    I really wish there was a way to know if LLMs hallucinate these switches incorrectly, like I do.

    Feels like this would be exactly the kind of thing they would get wrong. Fur exactly, the training set isn&#x27;t trained to know the context of execution (FreeBSD vs macos vs Linux), right?

    1. saidnooneever · · focus · HN ↗
      its trained to read both tekst and code which is enough to know the difference.

      appearently i am not :&#x27;) never knew there was -r

      1. hirvi74 · · focus · HN ↗
        I never knew there was a -R. =&#x27;)
  14. BobMontgomeryJr · · focus · HN ↗
    -h perhaps the only useful comment here. -R just looks baroque, but ls(1) might think it fine. I once read an article about the inconsistencies in *nix CLI commands, but the picture&#x27;s much better than hot-key and shortcut conflicts- &lt;which get silently absorbed by whatever&#x27;s running, no way to tell what they might&#x27;ve done or where they went..&gt; I hestitate to consult documentation, because of course there is non anymore. Why not Google it?
  15. BobMontgomeryJr · · focus · HN ↗

    [dead]

  16. dataflow · · focus · HN ↗
    Kind of off topic, but why in the world in 2026 do POSIX utilities still rely on global variables to pass around state? Is it too complicated to pass around a struct address in C or something?
    1. turtledragonfly · · focus · HN ↗
      I think there is a class of programs where globals are not so terrible. In particular, one-shot programs that do a task and then exit (like `ls`, `cp`, etc).

      You may also notice that some of these utilities will allocate memory, then never free it. They just let the OS handle that on program shutdown. That is also generally not recommended in arbitrary code. But again, it&#x27;s fine for a one-and-done sort of program.

      For these cases, the whole program is essentially one function call, and the global namespace is essentially the &quot;body&quot; of that function (hand waving a bit).

      It&#x27;s all a bit subjective, of course (:

      1. Bjartr · · focus · HN ↗
        Reminds me of the story of the memory leak in a missile guidance computer. It was determined that in the worst case scenario not enough memory could leak fast enough for it to be a problem between missile launch and impact. So they just let the explosion handle the garbage collection
    2. chasil · · focus · HN ↗
      It really doesn&#x27;t make and difference if the source for a utility exhibits terrible coding practices. If it passes the tests, then the OS can be certified.

      We&#x27;d prefer Rust versions with great forethought, but it&#x27;s irrelevant to the testing.

      There is no current version of Linux [uswrland] that maintains certified POSIX compliance. Only Apple, IBM, HP, and SCO are current?

      <a href="https:&#x2F;&#x2F;www.opengroup.org&#x2F;openbrand&#x2F;register&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.opengroup.org&#x2F;openbrand&#x2F;register&#x2F;

    3. kelnos · · focus · HN ↗
      [delayed]
    4. seba_dos1 · · focus · HN ↗
      Because why not? &quot;Globals bad&quot;? &quot;goto&quot; is still being used where it makes sense as well.

      It&#x27;s a good rule of thumb to avoid either of them, especially when you&#x27;re inexperienced yet, but they still have their uses.

    5. comex · · focus · HN ↗
      Many of those utilities, if you inspect the source code, are recognizably the same programs as their original versions written 30+ years ago. They’ve been maintained and changed over the years, sure, but they’ve rarely needed big changes. After all, they’re simple programs that do basically the same job today as they did then, using basically the same API surface.

      The main issue with this is that the programs are usually still single-threaded. For some key utilities like find and grep, this has allowed more modern alternatives to leapfrog them in performance. (To be fair, it’s hard to add parallelism without breaking compatibility somewhat.)

      But in most other respects, there’s nothing wrong with being a little old-fashioned. Using global variables is an example of that. It’s a problem in larger programs but at this scale it’s fine.

  17. souvlakee · · focus · HN ↗
    or -a?
  18. chasil · · focus · HN ↗
    The POSIX standard does not appear to support -r lowercase:

    <a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;

    1. mzhaase · · focus · HN ↗
      Wow, 24 years of Linux, I never bothered to look it up. Thanks.
  19. bitwize · · focus · HN ↗
    Slumming Pooh: cp -r

    Sophisticated Pooh: cp -a

  20. ddosmax556 · · focus · HN ↗
    For those that don&#x27;t know what &#x27;copy as regular file&#x27; means, it means the copy command opens any file as though it was a regular file. If you have a FIFO queue sitting around it will read the content of the FIFO queue - if nothing writes to it, the command will hang. If you do cp -r &#x2F;dev&#x2F;zero foo, it will write zeroes into foo until the disk is full. -R otoh will copy a fifo queue as a fifo queue.
  21. midtake · · focus · HN ↗
    Honestly I just rsync everything
  22. jasoneckert · · focus · HN ↗
    Historically, -R always meant recursive operation.

    However, some tools like cp starting using both -r and -R to mean recursive, and I imagine there are many newer tools where the author chose -r for recursive only.

    Things change over time.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.