スクリーンショット(名前にスペース含むファイル)をまとめて消すコマンド
% find . -name 'スクリーン*'
./スクリーンショット 2016-06-18 16.59.14.png
./スクリーンショット 2016-06-18 16.59.23.png
./スクリーンショット 2016-06-18 16.59.27.png
こんな状態のときに、まとめて消そうとして、以下のコマンドだとちょっとダメです。
% find . -name 'スクリーン*' | xargs rm
rm: ./スクリーンショット: No such file or directory
rm: 2016-06-18: No such file or directory
rm: 16.59.14.png: No such file or directory
rm: ./スクリーンショット: No such file or directory
rm: 2016-06-18: No such file or directory
rm: 16.59.23.png: No such file or directory
rm: ./スクリーンショット: No such file or directory
rm: 2016-06-18: No such file or directory
rm: 16.59.27.png: No such file or directory
ファイルにスペースが含まれているので、そこで区切られてrm
コマンドに渡ってしまいます。なので以下のようにします。
% find . -name 'スクリーン*' -print0 | xargs -0 rm
ありがとうございました。
参考
はじめてNUL文字を知りました。
man_xargs
-0 Change xargs to expect NUL (``\0'') characters as separators, instead of spaces and
newlines. This is expected to be used in concert with the -print0 function in
find(1).
man_find
-print0
This primary always evaluates to true. It prints the pathname of the current file
to standard output, followed by an ASCII NUL character (character code 0).
Author And Source
この問題について(スクリーンショット(名前にスペース含むファイル)をまとめて消すコマンド), 我々は、より多くの情報をここで見つけました https://qiita.com/mochizukikotaro/items/eb5cd5a643a183dc8c6d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .