再帰なしで検索する 質問する

再帰なしで検索する 質問する

findサブディレクトリに再帰しないような方法でコマンドを使用することは可能ですか? たとえば、

DirsRoot
  |-->SubDir1
  |    |-OtherFile1
  |-->SubDir2
  |    |-OtherFile2
  |-File1
  |-File2

そして、次のような結果find DirsRoot --do-not-recurse -type fになるでしょうかFile1, File2?

ベストアンサー1

-maxdepth 1現在のコマンド構造に基づいて、このオプションで必要な結果が得られると思います。そうでない場合は、マニュアルページのためにfind

関連エントリ(便宜上):

-maxdepth levels
          Descend at most levels (a non-negative integer) levels of direc-
          tories below the command line arguments.   `-maxdepth  0'  means
          only  apply the tests and actions to the command line arguments.

基本的に選択肢は次のとおりです:

# Do NOT show hidden files (beginning with ".", i.e., .*):
find DirsRoot/* -maxdepth 0 -type f

または:

#  DO show hidden files:
find DirsRoot/ -maxdepth 1 -type f

おすすめ記事