linux + リモートシステムの特定のファイルを除くファイルの検索 + 削除

linux + リモートシステムの特定のファイルを除くファイルの検索 + 削除

Redhat 7.2 Linuxバージョンがあります。

/etc/yum.repos.d/etc/yum.repos.d 以下のファイルを除いて、リモートシステム上のすべてのストレージファイルを削除したいと思います。

local.repo
redhat.repo
cluster.repo

私たちはこれを試しました(成功していません)

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

ベストアンサー1

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

(rootユーザーのログインシェルが$machineBourneに似ていると仮定します)。

コマンドに渡すのは、sshリモートホストで実行される引数ではなく、リモートユーザーのログインシェルからシェルコードとして解釈される文字列であることを覚えておいてください。したがって、最も簡単な方法は、文字列を一重引用符で囲み、ローカルシェルがそれを妨げないようにすることです。

おすすめ記事