find
/mnt
私はそれを使用するたびに常に完全に謎です。検索から除外したいのですが(WSLのUbuntu 20.04ではbashにあるので、Windows空間で検索したくありません)find
誤って進みます。そのディレクトリに入り、私を完全に無視します。このページで構文が見つかりました。https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-commandすべてのバリエーションを試しましたが、すべて失敗しました。
sudo find / -name 'git-credential-manager*' -not -path '/mnt/*'
sudo find / -name 'git-credential-manager*' ! -path '/mnt/*'
sudo find / -name 'git-credential-manager*' ! -path '*/mnt/*'
これによりエラーが発生し/mnt
、エラーが発生します(上記の構文は明確に見え、スタックオーバーフローページの構文は正しいと思われるので本当に残念です)。
find: ‘/mnt/d/$RECYCLE.BIN/New folder’: Permission denied
find: ‘/mnt/d/$RECYCLE.BIN/S-1-5-18’: Permission denied
find
誰かが私のディレクトリ除外スイッチを無視するのをやめる方法を教えてもらえますか?
ベストアンサー1
検索は-path
パスを除外しません。これは、「名前がこのパスに一致するものを報告しない」を意味します。それでもディレクトリにドロップダウンして検索されます。あなたが望むもの-prune
(からman find
):
-prune True; if the file is a directory, do not descend into it. If
-depth is given, then -prune has no effect. Because -delete
implies -depth, you cannot usefully use -prune and -delete to‐
gether. For example, to skip the directory src/emacs and all
files and directories under it, and print the names of the
other files found, do something like this:
find . -path ./src/emacs -prune -o -print
だからあなたは以下が欲しい:
sudo find / -path '/mnt/*' -prune -name 'git-credential-manager*'
-mount
除外するターゲットによっては、(GNU find
)または(その他)を使用する方が-xdev
簡単かもしれません。
からman find
:
-mount
他のファイルシステムのディレクトリをダウングレードしないでください。-xdev
他の find バージョンとの互換性のための代替名です。
だから:
sudo find / -mount -name 'git-credential-manager*'