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

查看:35
本文介绍了如何使用“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 the --exclude option. So, how can I achieve this?

推荐答案

rsync 快速简单:

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

--exclude 可以多次使用.

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

注意--exclude选项后面的thefoldertoexclude目录是相对于sourcefolder的,即sourcefolder/要排除的文件夹.

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天全站免登陆