LoginSignup
1
4

More than 5 years have passed since last update.

とても便利な`xargs`【随時更新】

Last updated at Posted at 2019-03-13

とても便利なxargsちゃん。かわいい。

何ができるの?

xargs - 標準入力を読み込んでコマンドラインを作成し、それを実行する

引用元: https://linuxjm.osdn.jp/html/GNU_findutils/man1/xargs.1.html

xargsはLinuxコマンドだけど、Windowsの場合はGit Bashとか使えば実行できる。ありがたきGit Bash。

活用方法

カレントディレクトリ配下を再帰的に見ながら全文検索

hogeが含まれるファイルってどこにあるんだろう」
「わざわざ全文検索するソフトとか入れたくないしな」
って時に便利。

bash
find . | xargs grep -sn "検索文字列"

カレントディレクトリ配下のファイルを全文検索して置換

hogefugaに変えたいけど、1ファイルずつ開くのアホらしいな」
「コマンド一発で、複数ファイルを一気に置換できんじゃろうか」
って時に便利。(以下のコマンドは再帰処理しない)

bash
grep -l '置換前文字列' ./* | xargs sed -i -e 's/置換前文字列/置換後文字列/g'

soon...

他にも便利なのあったら随時更新します。

1
4
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
1
4