使用 xargs 将查找结果中的目录 mv 到另一个目录中 [英] Use xargs to mv a directory from find results into another directory

查看:59
本文介绍了使用 xargs 将查找结果中的目录 mv 到另一个目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下命令:

find . -type d -mtime 0 -exec mv {} /path/to/target-dir ;

这会将创建的目录移动到另一个目录.我怎样才能使用 xargs 而不是 exec 来做同样的事情.

This will move the directory founded to another directory. How can I use xargs instead of exec to do the same thing.

推荐答案

如果你有 GNU mv(以及findxargs),可以使用-t选项到 mv(和 -print0 用于 find-0 用于 xargs):

If you've got GNU mv (and find and xargs), you can use the -t option to mv (and -print0 for find and -0 for xargs):

find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir

<小时>

请注意,现代版本的 find(与 POSIX 2008 兼容)支持 + 代替 ; 并且行为与 xargs 不使用 xargs:


Note that modern versions of find (compatible with POSIX 2008) support + in place of ; and behave roughly the same as xargs without using xargs:

find . -type d -mtime -0 -exec mv -t /path/to/target-dir {} +

这使得 find 将方便数量的文件(目录)名称组合到程序的单个调用中.您无法控制 xargs 提供的传递给 mv 的参数数量,但您实际上很少需要它.这仍然取决于 GNU mv-t 选项.

This makes find group convenient numbers of file (directory) names into a single invocation of the program. You don't have the level of control over the numbers of arguments passed to mv that xargs provides, but you seldom actually need that anyway. This still hinges on the -t option to GNU mv.

这篇关于使用 xargs 将查找结果中的目录 mv 到另一个目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆