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

前端 未结 13 1323
逝去的感伤
逝去的感伤 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:21

    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:

    find . -type f | xargs stat -c "%a %U:%G %n" | awk '{print "chown "$2" "$3"\nchmod "$1" "$3}' > ./filesPermissions.sh
    

    Example of output:

    chown root:root /file_or_folder_path
    chmod 777 /file_or_folder_path
    

提交回复
热议问题