config find コマンドは特定のディレクトリを除外します。

config find コマンドは特定のディレクトリを除外します。

findコマンドから特定のディレクトリを永久に除外するように設定する方法。https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command bashrcに次のエイリアスを追加してみました。

alias find='find -not \( -path ./.git -prune \)'

うまくいかないようです。

ripgrepでこれを設定できます。https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file それでは、gitのような特定のディレクトリを一度に除外するようにmake findを設定する方法は?

ベストアンサー1

myfind次のラッパースクリプトで作成します。

#! /bin/sh -
predicate_found=false skip_one=false
for arg do
  if "$skip_one"; then
    skip_one=false
  elif ! "$predicate_found"; then
    case $arg in
      (-depth | -ignore_readdir_race | -noignore_readdir_race | \
       -mount | -xdev | -noleaf | -show-control-chars) ;;
      (-files0-from | -maxdepth | -mindepth) skip_one=true;;
      (['()!'] | -[[:lower:]]?*)
        predicate_found=true
        set -- "$@" ! '(' -name .git -prune ')' '('
    esac
  fi
  set -- "$@" "$arg"
  shift
done
if "$predicate_found"; then
  set -- "$@" ')'
else
  set -- "$@" ! '(' -name .git -prune ')'
fi
exec find "$@"

オプションではなく、最初の述語の前に挿入し! ( -name .git -prune )(または述部が見つからない場合は最後に)、それを使用しないようにし、その間に(残りをラップします。)-o

たとえばにmyfind -L . /tmp /etc -maxdepth 1 -type d -o -printなりますfind -L . /tmp /etc -maxdepth 1 ! '(' -name .git -prune ')' '(' -type d -o -print ')'

pruneそれはみんな .git目次。 FreeBSDを使用して引数として渡されたディレクトリごとに深さ1のディレクトリのみを削除するfindには。-depth 1-name .git

.git-mindepth 2いくつか(または2より大きい数字)を追加すると、最終的にディレクトリに移動する可能性があります。

-pruneと結合(または暗黙)できないことに注意してください。-depth-delete-depth


1 ここで GNU を管理するfind オプション述部コンテンツの前にコンテンツを挿入すると、警告は表示されません。これにはヒューリスティックを使用します。 BSDを使うとだまされるmyfind -f -my-dir-starting-with-dash-...

おすすめ記事