V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
sheller
V2EX  ›  问与答

Mac 下 find 和 mv 组合命令失效的疑问

  •  
  •   sheller · 263 天前 · 562 次点击
    这是一个创建于 263 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需求描述

    把 A 文件夹下(包含子文件夹中的)所有后缀为docx文件移动到/Desktop/filedoc 目录下。

    使用命令

    在 A 文件夹中执行命令:find ./ -type f -name "*.docx" | xargs -0 mv ~/Desktop/filedoc

    但是这个命令并不生效,请问该如何写呢?

    6 条回复    2023-08-14 12:45:04 +08:00
    guog
        1
    guog  
       263 天前
    find . -type f -name '*.docx' | xargs -I {} mv {} ~/Desktop/filedoc
    sheller
        2
    sheller  
    OP
       263 天前
    @guog 只有一部分成功了,再执行一遍会出现 xargs: unterminated quote 的结果提示呢
    guog
        3
    guog  
       263 天前
    @sheller #2 估计是你文件名里面带有引号了吧,手动改下?
    lovestudykid
        4
    lovestudykid  
       263 天前
    chatgpt 的建议
    find ./ -type f -name "*.docx" -print0 | xargs -0 -I {} mv {} ~/Desktop/filedoc
    sheller
        5
    sheller  
    OP
       263 天前
    @guog 对,有很多文件名不规则,有的带引号,有的带空格
    @lovestudykid 谢谢我试试
    julyclyde
        6
    julyclyde  
       262 天前
    1 xargs 用了-0 但是前面 find 没有-print0
    2 mv 命令缺一个参数,那 xargs 默认会把那个参数补到末尾,这样看起来你会用 filedoc 文件覆盖掉各个 find 出来的文件

    如果你已经执行过了,建议先考虑一下第二个后果的问题,再继续研究
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   774 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 131ms · UTC 22:00 · PVG 06:00 · LAX 15:00 · JFK 18:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.