LoginSignup
0
0

More than 1 year has passed since last update.

特定の文字が含まれているファイルを1箇所にコピーしたい

Posted at

特定のファイルを1箇所に移動したい

目的

特定の文字が含まれているファイルを1箇所にコピーしたい

方法

find コマンドの exec オプションを使用する

使用例

$ find 検索パス -type f -name 検索したい名前 -ecec cp {} コピー先ディレクトリ \;

# 例
$ find . -type f -name "*.txt" -exec cp {} ~/dest \;

解説

findコマンド

  • type:ファイルタイプを指定する

    • -type fはファイルを対象として検索
    • -type dはディレクトリを対象として検索
  • name:ファイルの名前を指定する

    • ワイルドカードを使用して、ファイルやディレクトリ名の一部のみを指定し、検索することができる
      • "*.txt"はすべてのtextファイル
      • "test*/*.txt"はファイル名がtestで始まるすべてのtextファイル
  • -exec:検索結果に対してコマンドを実行する

    • {}は対象となる全ファイルを表し、最後の\;-execの終わりを表す記号
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0