You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用find+xargs cp批量移动PDF文件时出现cp: invalid option -- 'D'错误

解决cp命令报错"invalid option -- 'D'"的问题

错误原因

你遇到的错误是因为部分PDF文件名以-D开头,xargs会把文件名开头的-识别为cp命令的选项参数,导致cp无法正确解析。

解决方案

方法1:给cp添加--分隔符

通过--告诉cp命令,后续所有内容都是文件路径而非选项:

find /mnt/user/Data/01_Persönliche_Dokumente/01_Firmen -iname "*.pdf" -type f | xargs cp -t /mnt/user/Data/01_Persönliche_Dokumente/Paperless_input/ --

注:将\*.pdf改为"*.pdf",避免shell提前解析通配符,确保find能正确匹配所有PDF文件。

方法2:使用find的-exec选项(更可靠)

这种方式无需依赖xargs,能完美处理含特殊字符(如空格、连字符开头)的文件名:

  • 逐个处理文件:
find /mnt/user/Data/01_Persönliche_Dokumente/01_Firmen -iname "*.pdf" -type f -exec cp {} /mnt/user/Data/01_Persönliche_Dokumente/Paperless_input/ \;
  • 批量处理文件(效率更高):
find /mnt/user/Data/01_Persönliche_Dokumente/01_Firmen -iname "*.pdf" -type f -exec cp -t /mnt/user/Data/01_Persönliche_Dokumente/Paperless_input/ {} +

补充:如果是移动文件而非复制

将上述命令中的cp替换为mv即可,注意移动前确认目标目录无重名文件,避免数据覆盖。

内容的提问来源于stack exchange,提问作者Metti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 11:10:40