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

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

问题描述

我有以下命令:

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

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

mv (和 find xargs ),您可以使用 -t 选项来 mv (和 -print0 找到 -0 用于 xargs ):

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





$ b $注意现代版本的 find (与POSIX 2008兼容)支持 + 来代替; 并且与 xargs 大致相同,而不使用 xargs



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



<这使得将文件(目录)名称的方便号码组合成一个程序的单个调用。对于 xargs 提供的 mv 参数的数量,您没有控制级别,但您很少实际上无论如何都需要。这依然取决于GNU mv -t 选项。


I have the following command:

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

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

解决方案

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


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 {} +

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从一个目录中查找结果到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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