伏黛cp文:在Linux中使用cp时 如何避免“是同一文件”警告消息

我正在尝试将某些文件从一个目录复制到另一个目录。使用此命令

find "$HOME" -name '*.txt' -type f -print0 | xargs -0 cp -t $HOME/newdir

我收到一条警告消息说

cp:'/ home / me / newdir / logfile.txt' 和 '/ home / me / newdir / logfile.txt' 是同一个文件

如何避免此警告消息?

21

问题是您尝试将文件复制到其自身。您可以通过从 find 命令的结果中排除目标目录来避免它,如下所示:

find "$HOME" -name '*.txt' -type f -not -path "$HOME/newdir/*" -print0 | xargs -0 cp -t "$HOME/newdir" 
2

尝试使用install,这将首先删除文件。

install -v target/release/dynnsd-client target/
removed 'target/dynnsd-client'
'target/release/dynnsd-client' -> 'target/dynnsd-client'

然后删除源文件

1

使其在流程中独一无二。但这需要排序

find "$HOME" -name '*.txt' -type f -print0 | sort -zu | xargs -0 cp -t "$HOME/newdir"

或者,如果与生成的文件无关,请尝试使用cp-u选项。

find "$HOME" -name '*.txt' -type f -print0 | xargs -0 cp -ut "$HOME/newdir"
-u   copy only when the SOURCE file is newer than the destination file or when
     the destination file is missing
1

安装

在 Docker 的 Makefile 上下文中完美地工作-谢谢!

copy:  
    @echo ''  
    bash -c 'install -v ./docker/shell                   .'  
    bash -c 'install -v ./docker/docker-compose.yml      .'  
    bash -c 'install -v ./docker/statoshi                .'  
    bash -c 'install -v ./docker/gui                     .'  
    bash -c 'install -v ./docker/$(DOCKERFILE)   .'  
    bash -c 'install -v ./docker/$(DOCKERFILE_SLIM)        .'  
    bash -c 'install -v ./docker/$(DOCKERFILE_GUI)         .'   
    bash -c 'install -v ./docker/$(DOCKERFILE_EXTRACT) .'  
    @echo ''  
build-shell: copy  
    docker-compose build shell  

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(851)
Cindy不戴口罩的样子:谷歌视觉 API-如何检测人脸识别的人戴口罩
上一篇
如何申请ce认证:如何将Jira与GitLabCE集成
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(29条)