Forrest logo
back to the cp tool

cp:tldr:19459

cp: Recursively copy a directory's contents to another location (if the destination exists, the directory is copied inside it).
$ cp -R ${path-to-source_directory} ${path-to-target_directory}
try on your machine

This command is used to copy a directory and its contents from a source directory to a target directory.

Here's a breakdown of the command:

  • cp stands for "copy" and is the command to copy files or directories in Unix-like operating systems.
  • -R is an option that specifies that the copy operation should be recursive, which means it will copy not only the files but also the subdirectories and their contents.
  • ${path-to-source_directory} should be replaced with the actual path to the directory you want to copy. This is the source directory that contains the files and subdirectories you want to copy.
  • ${path-to-target_directory} should be replaced with the actual path to the directory where you want to copy the files and subdirectories. This is the target directory.

For example, if you wanted to copy the directory "documents" located in your home directory to a directory called "backup" also located in your home directory, the command would look like this:

cp -R /home/username/documents /home/username/backup

This would copy the "documents" directory and all its contents to the "backup" directory.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the cp tool