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.
Does that make sense?
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:
probably in combination with
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
to reset you iterate over your temp files, read permissions and chmod the actual files back.
I found best way (for me) do it with python!
backup acl: dump_acl.py -d /path/to/dir
recovery acl: dump_acl.py -r /path/to/dir
After execution, script create acl.json in the same dir(witch backup/restore acls)
Install the ACL package first:
Recursively store permissions and ownership to file:
Restore (relative to current path):
I modified Anton`s command to get the additional string chown user:group /file_or_folder_path. Now you can get a bash script which contains two string for each file/folder.
command:
Example of output:
I borrow this answer from roaima's post.
I think this should be the best answer:
Save the permissions
Restore the permissions
I found the answer from Dmytro L very cool. But, unfortunately, it's doesn't work, because it's generate entries like:
To avoid it, I use following command:
Basically, it does the same, but generate octal entries like:
which works.