如何使用"cp"命令排除特定目录? [英] How to use 'cp' command to exclude a specific directory?

查看:3443
本文介绍了如何使用"cp"命令排除特定目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要复制目录中的所有文件,但特定子目录中的某些文件除外. 我注意到'cp'命令没有--exclude选项. 那么,我该如何实现呢?

I want to copy all files in a directory except some files in a specific sub-directory. I have noticed that 'cp' command didn't have a --exclude option. So, how can I achieve this?

推荐答案

rsync快速简便:

rsync is fast and easy:

rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude

您可以多次使用--exclude.

rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude --exclude anotherfoldertoexclude

请注意,--exclude选项后的目录thefoldertoexclude是相对于sourcefolder的,即sourcefolder/thefoldertoexclude.

Note that the dir thefoldertoexclude after --exclude option is relative to the sourcefolder, i.e., sourcefolder/thefoldertoexclude.

您还可以添加-n以进行空运行,以查看在执行实际操作之前将要复制的内容,如果一切正常,请从命令行中删除-n.

Also you can add -n for dry run to see what will be copied before performing real operation, and if everything is ok, remove -n from command line.

这篇关于如何使用"cp"命令排除特定目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆