cp: -r or -R?

Hacker News Top Tools

Summary

一篇探讨 `cp` 命令中 `-r` 与 `-R` 选项历史差异的博文:两者在现代 GNU coreutils 中已无区别(2002 年合并),但 OpenBSD/NetBSD 仍保留行为差异,POSIX 推荐使用更一致的 `-R`。

No content available
Original Article
View Cached Full Text

Cached at: 10/03/26, 11:25 AM

# `cp`: `-r` or `-R`? Source: [https://movq.de/blog/postings/2026-09-30/0/POSTING-en.html](https://movq.de/blog/postings/2026-09-30/0/POSTING-en.html) [blog](https://movq.de/blog/)\-[git](https://movq.de/git/)\-[desktop](https://movq.de/desktop/)\-[contact](https://movq.de/contact.html) --- 2026\-09\-30 A 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\. Nowadays, there's no difference between the two options in GNU coreutils\. The current manual page says: ``` -R, -r, --recursive copy directories recursively ``` Was that always the case? Let'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: ``` case 'r': flag_recursive = 1; flag_copy_as_regular = 1; break; case 'R': flag_recursive = 1; flag_copy_as_regular = 0; break; ``` 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,[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\. What about other systems? OpenBSD 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`\)\. NetBSD 11:[Dito](https://github.com/NetBSD/src/blob/477d71b4d1b73a66b61a03b5f6d3dc9212d4f888/bin/cp/cp.c), manual page and code like OpenBSD\. The 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`: > 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\.

Similar Articles

@xiaofeilong99: Windows users, take note: Microsoft has released its own Coreutils. Commands like cat, cp, ls, mkdir, pwd, rm, sort, tee — which work perfectly on Linux/macOS but feel awkward on Windows — now have a native solution.

X AI KOLs Timeline

Microsoft has released Coreutils for Windows, a set of native Unix-style core tools (such as cat, cp, ls, etc.), aimed at reducing cross-platform script and development environment differences. It can be installed via WinGet and is currently in preview.

Replacing Ctrl-R in Bash without TIOCSTI

Lobsters Hottest

The article details a method to replace Bash's Ctrl-R history search using a custom tool, adapting to recent Linux kernel security changes that restrict TIOCSTI usage.

rsync and outrage

Lobsters Hottest

Rsync maintainer Andrew Tridgell defends his use of AI tools (Claude, Codex, Gemini) to improve security and rewrite the test suite, addressing backlash from the open-source community.