2014-01-28 10:53:43 +01:00
|
|
|
# cp
|
|
|
|
|
2019-02-11 19:00:49 +01:00
|
|
|
> Copy files and directories.
|
2024-12-13 08:55:04 -08:00
|
|
|
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html>.
|
2014-01-28 10:53:43 +01:00
|
|
|
|
2016-07-21 13:31:39 +01:00
|
|
|
- Copy a file to another location:
|
2014-01-28 10:53:43 +01:00
|
|
|
|
2020-07-25 05:19:46 -04:00
|
|
|
`cp {{path/to/source_file.ext}} {{path/to/target_file.ext}}`
|
2014-01-28 10:53:43 +01:00
|
|
|
|
2019-02-11 19:00:49 +01:00
|
|
|
- Copy a file into another directory, keeping the filename:
|
2014-01-28 10:53:43 +01:00
|
|
|
|
2020-07-25 05:19:46 -04:00
|
|
|
`cp {{path/to/source_file.ext}} {{path/to/target_parent_directory}}`
|
2014-01-28 10:53:43 +01:00
|
|
|
|
2019-04-19 02:54:58 +02:00
|
|
|
- Recursively copy a directory's contents to another location (if the destination exists, the directory is copied inside it):
|
2014-01-28 10:53:43 +01:00
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
`cp {{[-r|--recursive]}} {{path/to/source_directory}} {{path/to/target_directory}}`
|
2015-12-29 10:11:10 +08:00
|
|
|
|
2019-02-11 19:00:49 +01:00
|
|
|
- Copy a directory recursively, in verbose mode (shows files as they are copied):
|
2016-07-21 13:31:39 +01:00
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
`cp {{[-vr|--verbose --recursive]}} {{path/to/source_directory}} {{path/to/target_directory}}`
|
2016-07-21 13:31:39 +01:00
|
|
|
|
2023-04-10 10:49:34 +05:30
|
|
|
- Copy multiple files at once to a directory:
|
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
`cp {{[-t|--target-directory]}} {{path/to/destination_directory}} {{path/to/file1 path/to/file2 ...}}`
|
2023-04-10 10:49:34 +05:30
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
- Copy all files with a specific extension to another location, in interactive mode (prompts user before overwriting):
|
2017-04-18 22:47:41 +01:00
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
`cp {{[-i|--interactive]}} {{*.ext}} {{path/to/target_directory}}`
|
2020-05-13 01:54:45 +02:00
|
|
|
|
2021-04-27 23:02:42 +02:00
|
|
|
- Follow symbolic links before copying:
|
2020-05-13 01:54:45 +02:00
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
`cp {{[-L|--dereference]}} {{link}} {{path/to/target_directory}}`
|
2023-01-03 10:34:10 +07:00
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
- Use the full path of source files, creating any missing intermediate directories when copying:
|
2023-01-03 10:34:10 +07:00
|
|
|
|
2025-03-22 08:37:12 +02:00
|
|
|
`cp --parents {{source/path/to/file}} {{path/to/target_file}}`
|