<p>I want to delete all the files under the volume directory. The directory is inside the Kubernetes pod. So I am using the exec command.</p>

<p>My command - </p>

<pre><code>kubectl exec $POD -- rm -rf /usr/local/my-app/volume/*
</code></pre>

<p>The above command is not working. No output of the above command on terminal. I tried with below command and it is working -</p>

<pre><code>kubectl exec $POD -- rm -rf /usr/local/my-app/volume
</code></pre>

<p>But it will delete the directory. I can't delete the directory because it is using for mounting purpose.</p>

<p>How can I achieve the above functionalities?</p>

<p>Thanks</p>

lucy
<p>That's because the wildcard expansion is happening on <strong>your machine</strong> and not the Pod; what you want is to have the shell glob expand on the Pod, which one can accomplish via</p>

<pre class="lang-shell prettyprint-override"><code>kubectl exec $POD -- sh -c 'rm -rf /usr/local/my-app/volume/*'
</code></pre>
