What happened
Historically, GNU coreutils differentiated between the -r and -R options when copying directories recursively. The initial codebase from 1992 contained distinct handling for each, with -R explicitly designed to be synonymous with other recursive options within the suite.
This difference stemmed from early design considerations around consistency and user experience across different utilities. The cp command's source code (available in src/cp.c) reveals this divergence clearly: case 'r': flag_recursive = 1; flag_copy_as_regular = 1; break; case 'R': flag_recursive = 1; flag_copy_as_regular = 0; break;. This indicates that -r was intended to copy files as regular files, while -R was meant for full recursive descent. However, over time, these options were merged. Further investigation reveals a similar scenario with OpenBSD and NetBSD, where only -R is supported.
Why it matters
The preservation of this historical detail provides valuable insight into the development process of core utilities. It highlights how standards evolved (or didn't) across different Unix-like systems.
The divergence emphasizes the importance of clear design choices early on and how those choices can have lasting implications, even decades later. Understanding these nuances offers a deeper appreciation for the complexity underlying seemingly simple command-line tools.
But, but, but…
The current state reflects a deliberate consolidation around -R. OpenBSD, notably, has actively discouraged the use of -r due to its historical inconsistencies.
This decision was made for greater consistency across its utilities and adheres to the principles of POSIX standards, which recommend -R as the preferred method for recursive directory copying. The POSIX standard acknowledges this history with a clear recommendation. Ultimately, the story isn't just about two options; it’s about the tension between historical practices, evolving standards, and the deliberate choices made by different operating system vendors.
“‘The -R option was selected for consistency with all other options in this volume of POSIX.1-2024 that do recursive directory descent.’”
— Dr Non
The counter-take
The conflation of `-r` and `-R` represents a subtle but impactful deviation from best practices in Unix command-line tooling. While seemingly minor, it highlights the potential for inconsistencies within standardized systems, emphasizing the importance of careful design choices when creating robust and reliable utilities.
The AI angle
The shift in coreutils design demonstrates a recurring theme in software development: how legacy code and initial design decisions can persist even after significant changes. Similarly, AI-powered benchmark tools and automated testing could benefit from understanding these historical constraints within core system utilities to avoid unintended compatibility issues.
