{"article":{"slug":"cp-r-or-r","title":"cp: -r or -R?","subtitle":null,"summary":"A concise history of why Unix cp has both -r and -R, what POSIX says, and when the flags diverge across implementations.","content_type":"essay","language":"en","canonical_url":"https://movq.de/blog/postings/2026-09-30/0/POSTING-en.html","author":{"name":"movq","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"movq.de","url":"https://movq.de/","listing_slug":null,"listing":null},"topics":[{"name":"Programming","slug":"programming","url":"https://listedarticles.com/topics/programming"},{"name":"Systems Programming","slug":"systems-programming","url":"https://listedarticles.com/topics/systems-programming"},{"name":"Open Source","slug":"open-source","url":"https://listedarticles.com/topics/open-source"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":302,"reading_minutes":1,"published_at":"2026-09-30T00:00:00.000Z","added_at":"2026-10-03T12:12:53.240Z","updated_at":"2026-10-03T12:12:53.240Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/cp-r-or-r","markdown_url":"https://listedarticles.com/articles/cp-r-or-r.md","example":false,"citation":"movq, movq.de. \"cp: -r or -R?.\" 30 Sept 2026. https://movq.de/blog/postings/2026-09-30/0/POSTING-en.html (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://movq.de/blog/postings/2026-09-30/0/POSTING-en.html"},"body_markdown":"# `cp`: `-r` or `-R`?\n\n2026-09-30\n\nA question like this recently came up again. I once tried to find an answer, but only posted it in some \"forum\" a decade ago, and I think it's worth saving this little bit of trivia from digital nirvana.\n\nNowadays, there's no difference between the two options in GNU coreutils. The current manual page says:\n    \n    \n    -R, -r, --recursive\n        copy directories recursively\n    \n\nWas that always the case?\n\nLet's look at [the first commit in GNU coreutils](https://gitweb.git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=14fd34b78818660e05806b6eda178e3f846c5c21) (1992). In `src/cp.c`, we have this:\n    \n    \n    case 'r':\n        flag_recursive = 1;\n        flag_copy_as_regular = 1;\n        break;\n    \n    case 'R':\n        flag_recursive = 1;\n        flag_copy_as_regular = 0;\n        break;\n    \n\nSo, back then, there was indeed a difference. But that was 34 years ago. Is that still relevant today? Probably not, because ten years later, in 2002, [both options got merged](https://gitweb.git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=246e147a6a6b9d460376f7f7889191d13652456e) and nobody™ still runs coreutils from 24 years ago.\n\nWhat about other systems?\n\nOpenBSD 7.9 lists only `-R` in the manual and strongly discourages the use of `-r`. It does mention, though, that it still behaves differently than `-R`. Skim through [the code](https://github.com/openbsd/src/blob/f9782c23397ccf5cc0603f149c2b4e11dca8ad97/bin/cp/cp.c) and you can spot a few differences (search for `Rflag` and `rflag`).\n\nNetBSD 11: [Dito](https://github.com/NetBSD/src/blob/477d71b4d1b73a66b61a03b5f6d3dc9212d4f888/bin/cp/cp.c), manual page and code like OpenBSD.\n\nThe advantage of `-R` is that it's more consistent across utilities. For example, `chown` knows `-R` \\-- but not `-r`. [POSIX](https://pubs.opengroup.org/onlinepubs/9799919799/) acknowledges this as well and recommends `-R`:\n\n> Earlier versions of this standard included support for the `-r` option to copy file hierarchies. The `-r` option is historical practice on BSD and BSD-derived systems. This option is no longer specified by POSIX.1-2024 but may be present in some implementations. The `-R` option was added as a close synonym to the `-r` option, selected for consistency with all other options in this volume of POSIX.1-2024 that do recursive directory descent.","body_html":"<h1 id=\"cp-r-or-r\"><code>cp</code>: <code>-r</code> or <code>-R</code>?</h1>\n<p>2026-09-30</p>\n<p>A question like this recently came up again. I once tried to find an answer, but only posted it in some &quot;forum&quot; a decade ago, and I think it&#39;s worth saving this little bit of trivia from digital nirvana.</p>\n<p>Nowadays, there&#39;s no difference between the two options in GNU coreutils. The current manual page says:</p>\n<pre><code>-R, -r, --recursive\n    copy directories recursively</code></pre>\n<p>Was that always the case?</p>\n<p>Let&#39;s look at <a href=\"https://gitweb.git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=14fd34b78818660e05806b6eda178e3f846c5c21\" rel=\"nofollow ugc noopener\">the first commit in GNU coreutils</a> (1992). In <code>src/cp.c</code>, we have this:</p>\n<pre><code>case &#39;r&#39;:\n    flag_recursive = 1;\n    flag_copy_as_regular = 1;\n    break;\n\ncase &#39;R&#39;:\n    flag_recursive = 1;\n    flag_copy_as_regular = 0;\n    break;</code></pre>\n<p>So, back then, there was indeed a difference. But that was 34 years ago. Is that still relevant today? Probably not, because ten years later, in 2002, <a href=\"https://gitweb.git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=246e147a6a6b9d460376f7f7889191d13652456e\" rel=\"nofollow ugc noopener\">both options got merged</a> and nobody™ still runs coreutils from 24 years ago.</p>\n<p>What about other systems?</p>\n<p>OpenBSD 7.9 lists only <code>-R</code> in the manual and strongly discourages the use of <code>-r</code>. It does mention, though, that it still behaves differently than <code>-R</code>. Skim through <a href=\"https://github.com/openbsd/src/blob/f9782c23397ccf5cc0603f149c2b4e11dca8ad97/bin/cp/cp.c\" rel=\"nofollow ugc noopener\">the code</a> and you can spot a few differences (search for <code>Rflag</code> and <code>rflag</code>).</p>\n<p>NetBSD 11: <a href=\"https://github.com/NetBSD/src/blob/477d71b4d1b73a66b61a03b5f6d3dc9212d4f888/bin/cp/cp.c\" rel=\"nofollow ugc noopener\">Dito</a>, manual page and code like OpenBSD.</p>\n<p>The advantage of <code>-R</code> is that it&#39;s more consistent across utilities. For example, <code>chown</code> knows <code>-R</code> -- but not <code>-r</code>. <a href=\"https://pubs.opengroup.org/onlinepubs/9799919799/\" rel=\"nofollow ugc noopener\">POSIX</a> acknowledges this as well and recommends <code>-R</code>:</p>\n<blockquote><p>Earlier versions of this standard included support for the <code>-r</code> option to copy file hierarchies. The <code>-r</code> option is historical practice on BSD and BSD-derived systems. This option is no longer specified by POSIX.1-2024 but may be present in some implementations. The <code>-R</code> option was added as a close synonym to the <code>-r</code> option, selected for consistency with all other options in this volume of POSIX.1-2024 that do recursive directory descent.</p></blockquote>","headings":[{"level":1,"text":"cp: -r or -R?","id":"cp-r-or-r"}]}}