# Copy

| <mark style="color:yellow;">`cp [file] /dir`</mark>                   | Copy to /dir.                                                                                                                                                                                                                           |
| --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:yellow;">`cp [file] new_name`</mark>               | Rename                                                                                                                                                                                                                                  |
| <mark style="color:yellow;">`cp -r source_dir /dir`</mark>            | Recursive                                                                                                                                                                                                                               |
| <mark style="color:yellow;">`cp -p [file] /dir`</mark>                | Preserve its mode, ownership, and timestamps.                                                                                                                                                                                           |
| <mark style="color:yellow;">`cp -i [file] /dir`</mark>                | Interactively, prompting before overwrite.                                                                                                                                                                                              |
| <mark style="color:yellow;">`cp -v [file] /dir`</mark>                | Verbose output, showing the file names as they are copied.                                                                                                                                                                              |
| <mark style="color:yellow;">`cp -n [file] /dir`</mark>                | No Clobber. Won't overwriting any existing file in the target location.                                                                                                                                                                 |
| <mark style="color:yellow;">`rsync -av [file] /dir`</mark>            | Archive mode to preserve permissions and verbose output.                                                                                                                                                                                |
| <mark style="color:yellow;">`rsync -av --progress [file] /dir`</mark> | Displays progress.                                                                                                                                                                                                                      |
| <mark style="color:yellow;">`rsync -av --delete /src_dir /dir`</mark> | Sync contents of <mark style="color:yellow;">`/src_dir`</mark> to <mark style="color:yellow;">`/dir`</mark>, deleting files in <mark style="color:yellow;">`/dir`</mark> that are not in <mark style="color:yellow;">`/src_dir`</mark>. |
| <mark style="color:yellow;">`rsync -av --dry-run [file] /dir`</mark>  | Simulate the file copy operation without actually copying any files. Useful for checking what will be copied.                                                                                                                           |

Copy over SSH to a remote system, compressing file data during the transfer:

```bash
rsync -avz -e ssh [file] user@remote_host:/dir
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.shellspells.net/linux/file-ops/copy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
