Sync Linux File Permissions

5. Dec 2017

Sync Linux File Permissions

I ran into the situation where I had a directory tree restored from backup but the permissions were all messed up. The directory with the corrupted files still existed and the permissions there were intact.

So the idea was to sync the permissions of the one directory tree to the other. I found the solution to my problem in this Serverfault thread.

The way this works is to read the permissions recursively with getfacl, store the result in a file, change the path with sed and then run setfacl with the file as input.

getfacl -R /path/to/dirtree > permissions.acl

sed -i s/olddir/newdir/g permissions.acl

setfacl --restore=permissions.acl

Feel free to take a look into permissions.acl before and after using sed and pay attention from where you run the commands in case you use relative paths.

Got any hints or questions? blog@aaronlauterer.com