Is it possible to create a script to save and restore permissions?

前端 未结 13 1487
逝去的感伤
逝去的感伤 2021-01-30 04:29

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 t

13条回答
  •  半阙折子戏
    2021-01-30 05:15

    I borrow this answer from roaima's post.
    I think this should be the best answer:
    Save the permissions

    find * -depth -exec stat --format '%a %u %g %n' {} + >/tmp/save-the-list
    

    Restore the permissions

    while read PERMS OWNER GROUP FILE
    do
        chmod "$PERMS" "$FILE"
        chown "${OWNER}:${GROUP}" "$FILE"
    done 

提交回复
热议问题