LoginSignup
98
67

More than 5 years have passed since last update.

xargs で標準入力が空だったら何もしない

Last updated at Posted at 2012-03-16

find /hoge/fuga -ctime +30 -type f -print | xargs rm

などしたときに、何もfindの条件にマッチしなかったら、単に引数なしのrmが実行され

rm: missing operand
Try `rm --help' for more information.

となる。

こういったエラーを出したくない場合は、--no-run-if-empty を使って

find /hoge/fuga -ctime +30 -type f -print | xargs --no-run-if-empty rm

としてやると、findの結果が空の場合は、rmが実行されず、エラーも出ない。

98
67
1

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
98
67