I'm looking for the difference between cp -r
and cp -a
. What does "recursive" mean in terms of copying files from a folder?
Linux – Difference between cp -r and cp -a
cplinuxrecursive
Related Solutions
While -R
is posix well-defined, -r
is not portable!
On Linux, in the GNU and BusyBox implementations of cp
, -r
and -R
are equivalent.
On the other side, as you can read in the POSIX manual page of cp
, -r
behavior is implementation-defined.
* If neither the -R nor -r options were specified, cp shall take actions based on the type and contents of the file referenced by the symbolic link, and not by the symbolic link itself. * If the -R option was specified: * If none of the options -H, -L, nor -P were specified, it is unspecified which of -H, -L, or -P will be used as a default. * If the -H option was specified, cp shall take actions based on the type and contents of the file referenced by any symbolic link specified as a source_file operand. * If the -L option was specified, cp shall take actions based on the type and contents of the file referenced by any symbolic link specified as a source_file operand or any symbolic links encoun- tered during traversal of a file hierarchy. * If the -P option was specified, cp shall copy any symbolic link specified as a source_file operand and any symbolic links encoun- tered during traversal of a file hierarchy, and shall not follow any symbolic links. * If the -r option was specified, the behavior is implementation- defined.
Each platform you support comes with an associated cost. Typically you require:
- A build environment
- A separate test environment (for example, not having the development tools installed)
- Additional time to build and test new releases
- Additional resources to support each platform
CentOS aims to be binary compatible with Red Hat which lessens the need for a separate build environment. However, if you don't also have access to a CentOS environment, at least for testing, you might get caught out by subtle differences. Theoretically you might be unable to reproduce an issue that occurs on a user's CentOS installation on your Red Hat installation.
You might also have to provide different installation instructions for dependencies due to the different repository organisation.
Repository Organisation
Red Hat as of RHEL 7 has split things up into many more repositories:
- atomic host
- server
- workstation
- optional variants of the above
- supplementary repos for the above
- beta repos for the above
In fact I count no less than 85 (as follows):
>yum repolist all | grep rhel | wc -l
85
This does not seem to be the case for CentOS 7 (please correct me if I'm wrong)
Moreover things available in one RHEL repository are not compatible with some of the others. For example, docker from atomichost does not play well on my workstation install.
Java
This post from 2016 mentions that (Oracle) Java cannot be installed directly on CentOS:
Red Hat has a contract with Oracle to redistribute Oracle Java SE binaries (including the JDK and JRE) and to support those products as part of a RHEL subscriptions. CentOS does not ship Oracle Java SE; CentOS users who wish to use Oracle Java SE must download and install it directly from Oracle.
Security Patches
Security patches are generally applied to CentOS very quickly:
- How long after Red Hat publishes a fix does it take for CentOS to publish a fix?
Our goal is to have individual RPM packages available on the mirrors within 72 hours of their release, and normally they are available within 24 hours. Occasionally packages are delayed for various reasons. On rare occasions packages may be built and pushed to the mirrors but not available via yum. (This is because yum-arch has not been run on the master mirror. This may happen when issues with upstream packages are discovered shortly after their release, and if releasing the package would break it's functionality.)
Red Hat provide extended life-cycle support for older versions (at additional cost). This means that you can get patches for critical CVEs for RHEL 5 while CentOS can simply write off CentOS 5 as no longer supported. Notably there have been several critical CVEs affecting RHEL 5 since it (and CentOS 5) reached end of life.
See also Is CentOS exactly the same as RHEL?
Docker
With the rise of Docker we have a new difference:
Docker Community Edition (Docker CE) is not supported on Red Hat Enterprise Linux.
You must instead buy Docker EE license. You can install Docker-CE on RHEL using the CentOS repositories. See install Docker CE 17.03 on RHEL7
But this is obviously an unsupported configuration.
This is an odd one as that decision is made by the Docker team and not Red Hat. So presumably Red Hat could decide to support Docker CE if they wanted to?
The essential difference between them is still the same:
If you want commercial support and certification you need to pay for it (use Red Hat) If you don't want it you can use CentOS.
Direction
From the CentOS FAQ:
Red Hat and the CentOS Project are building a new CentOS, capable of driving forward development and adoption of next-generation open source projects.
This is corporate blurb but it could be taken as meaning Red Hat want RHEL to diverge from CentOS in some interesting but unspecified way.
Update: Dec-2020
The direction for CentOS is now clearer:
- CentOS 8 is to be end of lifed early (2021).
- CentOS 7 support continues until 2024.
- RedHat (now owned by IBM) will no longer provide a CentOS that competes with RHEL.
- They now have "CentOS stream" which is upstream from RedHat and acts a bit like a beta.
The best summary is probably - https://hackaday.com/2020/12/09/centos-is-dead-long-live-centos/
See also:
- https://blog.centos.org/2020/12/future-is-centos-stream/ - especially note the user comments
- https://wiki.centos.org/About/Product
- https://endoflife.date/centos
- https://www.techrepublic.com/article/why-the-shift-from-centos-to-centos-stream-is-a-big-mistake/
The eagle eyed may note that Fedora is an upstream version of RedHat. So where does CentOS stream fit? To explain the difference lwn says:
“If the distros were wooden furniture, RHEL would be a finished desk, Stream would be the unpainted and unsanded desk, and Fedora would be the tree.”
A further explanation and more positive spin on the split is given by:
To fill the niche CentOS used to fill some of the original CentOS team are creating Rocky Linux - https://github.com/rocky-linux/rocky outside of RedHat.
There are some other notable projects that already existed independently of CentOS and may fill a similar niche.
Best Answer
Recursive means that
cp
copies the contents of directories, and if a directory has subdirectories they are copied (recursively) too. Without-R
, thecp
command skips directories.-r
is identical with-R
on Linux, it differs in some edge cases on some other unix variants.By default,
cp
creates a new file which has the same content as the old file, and the same permissions but restricted by the umask; the copy is dated from the time of the copy, and belongs to the user doing the copy. With the-p
option, the copy has the same modification time, the same access time, and the same permissions as the original. It also has the same owner and group as the original, if the user doing the copy has the permission to create such files.The
-a
option means-R
and-p
, plus a few other preservation options. It attempts to make a copy that's as close to the original as possible: same directory tree, same file types, same contents, same metadata (times, permissions, extended attributes, etc.).