你並不需要使用xargs
,find
可以在比賽中執行命令:
find ~/Desktop -name 「*.jpg」 -o -name 「*.gif」 -o -name 「*.png」 -exec mv \{\} ~/Pictures \;
可以-exec
後逃脫的分號\;
之前發出命令。 \{\}
被替換爲匹配的文件名。
從man find
:
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered. The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a '\') or quoted to protect them from expansion by the shell. See the EXAMPLES section for examples of the use of the -exec option. The specified command is run once for each matched file. The command is executed in the starting directory. There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead.
注意,分號和{}必須進行轉義。
來源
2016-01-31 07:10:29
e0k
如果你想所有的圖像文件從桌面移動到一個特定的目錄只使用'-exec MV \ {\} 〜/圖片\;'在find的末尾(沒有管道和xargs和print0) – pouyan
你正在使用[tag:linux]標籤,但你真的使用Linux(和GNU'xargs'和'mv')嗎? BSD版本(也在[Mac OS X]上(https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/mv.1.html))有不同的選項。 – e0k