特定のテキストを含むファイルを検索し、そのファイルを別のディレクトリにコピーします。

特定のテキストを含むファイルを検索し、そのファイルを別のディレクトリにコピーします。

特定のテキストを含むファイルをディレクトリから検索して別のディレクトリにコピーする方法は? .kshシェルを使用しています。

ベストアンサー1

そして旗をman xargs見てください。-I

find /path/to/directory -type f -exec grep -il "your pattern" {} \; | xargs -I % cp % /dest/dir/

入力を保存するには、次のコマンドをシェルスクリプトに入力します。

#!/usr/bin/ksh 
# Script name: locate
find /path/to/directory -type f -exec grep -il "$1" {} \; | xargs -I % cp % /dest/dir/

実行するには、検索したいテキストの場所を入力してくださいlocate searchstringsearchstring

おすすめ記事