<p>For Windows to Linux, the following commands worked for me (this will not accept backslash, only forward-slash worked):</p>
<pre><code>kubectl cp C:/myfiles/azureCLI/WantToCopy my-pod:/mnt/data/something/
</code></pre>

CC BY-SA 4.0
2021-07-07T02:54:17.510Z
2021-07-08T05:30:52.927Z
2021-07-08T05:30:52.927Z
yuvraj
<p>According to the help menu, the recursive option does not seem to exist.</p>

<pre><code>user@localhost ~ $ kubectl cp --help
Copy files and directories to and from containers.

Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'kubectl cp' will fail.

  # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  kubectl cp /tmp/foo_dir &lt;some-pod&gt;:/tmp/bar_dir

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  kubectl cp /tmp/foo &lt;some-pod&gt;:/tmp/bar -c &lt;specific-container&gt;

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace &lt;some-namespace&gt;
  kubectl cp /tmp/foo &lt;some-namespace&gt;/&lt;some-pod&gt;:/tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl cp &lt;some-namespace&gt;/&lt;some-pod&gt;:/tmp/foo /tmp/bar

Options:
  -c, --container='': Container name. If omitted, the first container in the pod will be chosen

Usage:
  kubectl cp &lt;file-spec-src&gt; &lt;file-spec-dest&gt; [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
</code></pre>

<p>In order to copy files recursively, all files could be put in a directory and when this folder is copied to the pod, all files were copied:</p>

CC BY-SA 3.0
2018-01-19T19:26:12.683Z
2018-01-19T19:55:12.837Z
2018-01-19T19:55:12.837Z
030
<p><code>-r</code> is not needed to copy the folder. The below command will work. I tested this on <code>kubectl</code> version 1.21.</p>
<pre><code>kubectl cp &lt;pod_id&gt;:/home/test_folder test_folder_localhost
</code></pre>

CC BY-SA 4.0
2021-05-10T09:35:25.430Z
2021-05-10T15:56:56.757Z
2021-05-10T15:56:56.757Z
Nikhil
<p><code>kubectl cp</code> by default does recursive copies when given a directory, although it seems to be picky about trailing slashes.  If <code>foo/bar</code> is the directory you'd like to copy, simply run</p>
<pre><code>kubectl cp /path/to/foo/bar &lt;pod-id&gt;:/path/in/container/foo/
</code></pre>

CC BY-SA 4.0
2024-07-26T10:55:39.027Z
This does not overwrite existing.
safetyduck
CC BY-SA 4.0
2018-09-07T23:14:05.917Z
on win: `kubectl cp C:/myfiles/azureCLI/WantToCopy/* my-pod:/mnt/data/something/`
TiloBunt
CC BY-SA 4.0
2018-01-26T23:14:14.493Z
2021-07-22T05:01:07.390Z
2021-07-22T05:01:07.390Z
Xiong Chiamiov
<p>I want to copy files recursively to a Kubernetes pod</p>

<p>I tried <code>kubectl cp -r</code></p>

<p>I got:
<code>error: unknown shorthand flag: 'r' in -r</code></p>

<p>What are the best ways to transfer whole directories recursively into a pod.</p>

<kubernetes>
How to copy files recursively to a Kubernetes pod?
David West
# How to copy files recursively to a Kubernetes pod?

(Asked by: username_0 on 2018-01-19)

I want to copy files recursively to a Kubernetes pod

I tried `kubectl cp -r`

I got:
`error: unknown shorthand flag: 'r' in -r`

What are the best ways to transfer whole directories recursively into a pod.

**Tags:** kubernetes


---

## 4 answers

### Answer by username_4 on 2018-01-26. Score: 39 | Accepted answer

kubectl cp by default does recursive copies when given a directory, although it seems to be picky about trailing slashes.  If foo/bar is the directory you'd like to copy, simply run
kubectl cp /path/to/foo/bar :/path/in/container/foo/

> **Comments:**
> **username_6**: on win: `kubectl cp C:/myfiles/azureCLI/WantToCopy/* my-pod:/mnt/data/something/`  
> **username_5**: This does not overwrite existing.  

---

### Answer by username_1 on 2021-07-07. Score: 1

For Windows to Linux, the following commands worked for me (this will not accept backslash, only forward-slash worked):
kubectl cp C:/myfiles/azureCLI/WantToCopy my-pod:/mnt/data/something/


---

### Answer by username_2 on 2018-01-19. Score: 0

According to the help menu, the recursive option does not seem to exist.
user@localhost ~ $ kubectl cp --help
Copy files and directories to and from containers.

Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'kubectl cp' will fail.

  # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  kubectl cp /tmp/foo_dir :/tmp/bar_dir

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  kubectl cp /tmp/foo :/tmp/bar -c 

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace 
  kubectl cp /tmp/foo /:/tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl cp /:/tmp/foo /tmp/bar

Options:
  -c, --container='': Container name. If omitted, the first container in the pod will be chosen

Usage:
  kubectl cp   [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

In order to copy files recursively, all files could be put in a directory and when this folder is copied to the pod, all files were copied:


---

### Answer by username_3 on 2021-05-10. Score: 0

-r is not needed to copy the folder. The below command will work. I tested this on kubectl version 1.21.
kubectl cp :/home/test_folder test_folder_localhost


---

