在linux上递归移动文件
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
find
命令上使用-print0
而不是-print
,并且 xargs-0
(或--null
) 选项 - 那么 NUL 将用作分隔符而不是换行符和空格。Use
-print0
instead of-print
on thefind
command, and the xargs-0
(or--null
) option - then NULs will be used as separators rather than newlines and spaces.您看过 find 的 -exec 选项吗?
-exec 选项将执行其后面的任何选项作为命令,直到看到用引号引起来的分号。这样您就不必处理间距问题。
Have you looked at the -exec option for find?
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.
GNU 查找
GNU find