复制文件的权限,但不能删除文件 [英] Copy file permissions, but not files

查看:164
本文介绍了复制文件的权限,但不能删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有同样的目录树的两个副本。他们几乎有两个相同的文件(一个版本可能有一对夫妇额外的或丢失的文件)。但是,大多数文件都是常见的两个目录(有相同的相对路径和一切)。

I have two copies of the same directory tree. They almost have the same files in both (one version may have a couple extra or missing files). However, most of the files are in common to both directories (have the same relative paths and everything).

假设这些都是目录:

version1/
version2/

问题是,在VERSION1权限/弄乱了,我想在从版本2 /权限复制,但这样做没有替换VERSION1 /文件这是新的。

The problem is that the permissions in version1/ got messed up, and I would like to copy over the permissions from version2/, but do it without replacing the files in version1/ which are newer.

是否有一个自动化的方式通过的bash做到这一点? (这并不必须是bash的,也可能是一些其他方法/编程语言以及)。

Is there an automated way to do this via bash? (It doesn't have to be bash, it could be some other method/programming language as well).

推荐答案

您应该看一看在 - 为的选项=HTTP:/ /linux.die.net/man/1/chmod> 搭配chmod

You should have a look at the --reference option for chmod:

chmod --reference version2/somefile version1/somefile

应用找到的xargs 以固定方式,你应该罚款,即像

Apply find and xargs in a fitting manner and you should be fine, i.e. something like

 ~/version2$ find . -type f | xargs -I {} chmod --reference {} ../version1/{}

这甚至可以递归,并反对在目标目录中丢失的文件稳健(棒材的没有这样的文件... 的错误,这可以忽略不计)。当然,它不会做任何文件,只有在目标目录中。

This even works recursively, and is robust against missing files in the target directory (bar the No such file ... errors, which can be ignored). Of course it won't do anything to files that only exist in the target directory.

干杯,

这篇关于复制文件的权限,但不能删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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