openshiftopenshift-client-tools

How to delete files/directories using oc cli in Openshift


I've used oc cp to copy files and directories onto a persistent volume attached to a pod in my openshift project. Is there any way to delete?


Solution

  • You can use oc exec to execute any command inside the container, so you can use the following to execute rm within the container to delete files:

    oc exec <pod-name> rm /path/to/my-file
    

    or to recursively delete a folder within the container:

    oc exec <pod-name> rm -rf /path/to/my/directory
    

    Alternatively, you can use oc rsh <pod-name> to open an interactive terminal if the Pod contains a shell binary.