是否可以创建一个脚本来保存和恢复权限? [英] Is it possible to create a script to save and restore permissions?

查看:68
本文介绍了是否可以创建一个脚本来保存和恢复权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用linux系统,需要对一组嵌套文件和目录进行一些权限试验.我想知道是否有某种方法可以在不保存文件本身的情况下保存文件和目录的权限.

I am using a linux system and need to experiment with some permissions on a set of nested files and directories. I wonder if there is not some way to save the permissions for the files and directories, without saving the files themselves.

换句话说,我想保存权限,编辑一些文件,调整一些权限,然后将这些权限恢复到目录结构中,以将更改的文件保留在原位.

In other words, I'd like to save the perms, edit some files, tweak some permissions, and then restore the permissions back onto the directory structure, keeping the changed files in place.

这有意义吗?

推荐答案

hm.所以你需要 1)读取文件权限 2)以某种方式存储它们,并将其与每个文件相关联 3)阅读您存储的权限并将其重新设置

hm. so you need to 1) read file permissions 2) store them somehow, associated to each file 3) read your stored permissions and set them back

不是完整的解决方案,但有一些想法:

not a complete solution but some ideas:

stat -c%a filename
>644

可能与

find -exec

要存储此信息,这个问题有一些有趣的想法.基本上,您将创建一个与实际文件匹配的临时文件结构,每个临时文件均包含文件许可权

to store this information, this so question has some interesting ideas. basically you create a temporary file structure matching your actual files, with each temp file containing the file permissions

要重置,您可以遍历临时文件,读取权限并将chmod更改为实际文件.

to reset you iterate over your temp files, read permissions and chmod the actual files back.

这篇关于是否可以创建一个脚本来保存和恢复权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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