This question already has an answer here:

we have redhat 7.2 Linux version

I want to remove on remote machines all repositories files under /etc/yum.repos.d except the following files under /etc/yum.repos.d


we tried this ( but without success )

ssh root@$machine find /etc/yum.repos.d  -type f -not -name 'local.repo ' -or -name 'redhat.repo' -or -name ' cluster.repo’  –delete


ssh root@$machine find /etc/yum.repos.d  ! -name 'local.repo|redhat.repo|cluster.repo' -type f -exec rm -f {} +


ssh root@$machine find   /etc/yum.repos.d -type f -not \(-name 'local.repo'  -or -name 'redhat.repo' -or -name 'cluster.repo' \) -delete

marked as duplicate by muru, roaima, Fabby, Anthony G - justice for Monica, X Tian Jul 10 at 12:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Your sequence of -or ... should be wrapped in parentheses – muru Jul 7 at 9:50
  • this is not duplicate , this is diff question we want to delete files on remote machine and exclude some files , – yael Jul 7 at 9:51
  • 1
    Looks like a duplicate to me – roaima Jul 7 at 11:23
ssh "root@$machine" '
   find /etc/yum.repos.d -type f ! \(
     -name local.repo -o \
     -name redhat.repo -o \
     -name cluster.repo \) –delete

(assuming the login shell of the root user on $machine is Bourne-like).

Remember what you're passing to ssh is not the arguments of a command to run on the remote host, but a string that is interpreted as shell code by the login shell of the remote user. So the easiest is to put that string inside single quotes so the local shell doesn't interfere with it.

  • what you think about my answer , its similar to your answer – yael Jul 7 at 10:22
  • @yael, yes that works as well. – Stéphane Chazelas Jul 7 at 10:58

this CLI will remove all files under /etc/yum.repos.d , exclude the files , and also will print the files that are deleted

ssh "root@$IP" "find  /etc/yum.repos.d ! -name local.repo ! -name redhat.repo ! -name cluster.repo    -type f -delete -print"

Not the answer you're looking for? Browse other questions tagged or ask your own question.