开发者

What's the most efficient way to move multiple wildcards in bash?

Wha开发者_如何学Ct's the most efficient way to rewrite the following:

mv *.jpg ~/Pictures && mv *.gif ~/Pictures && mv *.png ~/Pictures


You can group into one

mv *.{jpg,gif,png} ~/Pictures

If you are worrying too many files causing argument list too long

find -regex ".*\.\(jpg\|gif\|png\)" -print0 | xargs -r0 mv --target='~/Pictures'


Efficient? Any efficiencies in the calculations of the file names is likely to be swamped by the actual copying, but you could try:

mv *.jpg *.gif *.png ~/Pictures

If you're talking a lot of files, you'll have to watch out for blowing the command line size limit, but then you'd probably look into using find and xargs (I won't complicate the solution by describing that fully, especially since there's probably an answer to that expanded question elsewhere on the SO network).


shopt -s nocaseglob
mv *.{jpg,gif,png} ~/Pictures
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜