在linux上递归移动文件

发布于 2024-08-17 06:45:13 字数 406 浏览 12 评论 0原文

find ./dir -type f -iname "*.t[argz]*[bz2]" -print | xargs mv --target-directory=dir 名称中包含空格的文件似乎失败。 如何改进呢?或者替代方案?

感谢下面的回答:我的 mv 不支持 --null 或 -0,我正在使用 cygwin:

$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Mandatory arguments t
.

find ./dir -type f -iname "*.t[argz]*[bz2]" -print | xargs mv --target-directory=dir
seems to fail on file that has spaces in the name.
how to improve it? or alternative?

thanks for answer below: my mv doesn't support --null or -0, I'm using cygwin:

$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Mandatory arguments t
.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我还不会笑 2024-08-24 06:45:13

find 命令上使用 -print0 而不是 -print,并且 xargs -0 (或 --null) 选项 - 那么 NUL 将用作分隔符而不是换行符和空格。

find ./dir -type f -iname "*.t[argz]*[bz2]" -print0 | xargs --null mv --target-directory=dir

Use -print0 instead of -print on the find command, and the xargs -0 (or --null) option - then NULs will be used as separators rather than newlines and spaces.

find ./dir -type f -iname "*.t[argz]*[bz2]" -print0 | xargs --null mv --target-directory=dir
醉城メ夜风 2024-08-24 06:45:13

您看过 find 的 -exec 选项吗?

find ./dir -type f -iname "*.t[argz][bz2]" -exec mv {} --target-directory=dir ';' 

-exec 选项将执行其后面的任何选项作为命令,直到看到用引号引起来的分号。这样您就不必处理间距问题。

Have you looked at the -exec option for find?

find ./dir -type f -iname "*.t[argz][bz2]" -exec mv {} --target-directory=dir ';' 

The -exec option will execute any options following it as a command until it sees the semi-colon wrapped in quotes. This way you won't have to deal with the spacing issue.

幸福%小乖 2024-08-24 06:45:13

GNU 查找

find ./dir -type f -iname "*.t[argz]*[bz2]" -exec mv "{}" /destination +;

GNU find

find ./dir -type f -iname "*.t[argz]*[bz2]" -exec mv "{}" /destination +;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文