Linuxで検索コマンド

Linuxで検索コマンド

私の友人は、-rスイッチを使用してディレクトリとサブディレクトリで繰り返しファイルを見つけることができると言いました。与えられた文のエラーを教えてください。動作しません。

find / -type f -r -name "abc.txt"

ベストアンサー1

うまくいかないのは、findに-rオプションがないからです。多くのプログラムでは、このフラグは「再帰的」を意味しますが、すべてのプログラムに該当するわけでは-rありませんfindfindいいえ再帰的でありますように。

このコマンドを使用して、ほとんどのプログラムのオプションを確認できますman。たとえば、man find。 findマニュアルが膨大であるため、オプションを見つけるためにマニュアルを検索する必要があるかもしれません-r

$ man find | grep -w -- -r

- grepにオプションの読み取りを停止するように指示します。それ以外の場合、-r はオプションで grep に渡されます。また、/検索したい項目をクリックして作成し、入力してマニュアルページ内で検索することもできます。

このコマンドは何も返しません。次のマニュアルを検索するコマンドと比較してくださいcp

$ man cp | grep -w -- -r
   -R, -r, --recursive

常に再帰的であるため、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.

   -mindepth levels
          Do  not apply any tests or actions at levels less than levels (a
          non-negative integer).  -mindepth  1  means  process  all  files
          except the command line arguments.

したがって、コマンドに関する質問があるときはいつでもそのmanページを読んでください。特定のオプションの機能が何であるかがわからないためです。たとえば、

$ man sort | grep -w -- -r
   -r, --reverse
$ man mount | grep -w -- -r,
   -r, --read-only
$ man awk | grep -A 8 -w -- -r
  -r
  --re-interval
          Enable the use of interval  expressions  in  regular  expression
          matching (see Regular Expressions, below).  Interval expressions
          were not traditionally available in the AWK language.  The POSIX
          standard  added them, to make awk and egrep consistent with each
          other.  They are enabled by default, but this option remains for
          use with --traditional.
$ man sed | grep -w -- -r
   -r, --regexp-extended
$ man xterm | grep -w -- -r
   -r      This option indicates that reverse video should be simulated by
           swapping the foreground and background colors. 

あなたは理解しました。

おすすめ記事