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

前端 未结 13 1362
逝去的感伤
逝去的感伤 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条回答
  •  旧时难觅i
    2021-01-30 05:00

    #!/bin/bash
    
    if [ $# -ne 1 ]; then
            echo "Enter directory";
            exit 0;
    fi
    # dump acls
    cd $1
    >acl
    echo "#!/bin/bash">recovery_acl.sh
    echo "cd $1">>recovery_acl.sh
    f='./'
    # create acl file sorted by dir_level
    for i in `seq 0 15`;do
      find . -mindepth $i -maxdepth $i -type d -exec getfacl {} +|grep -E '*UTS|file:'>>acl
    done
    sed -i 's/default\:user/\-dm\ u/g' acl
    sed -i 's/default\:group/\-dm\ g/g' acl
    sed -i 's/user\:/\-m\ u\:/g' acl
    sed -i 's/group\:/\-m\ g\:/g' acl
    sed -i 's/\#\ file\:\ /\.\//g' acl
    sed -i '/^#/d' acl
    
    while IFS='' read -r line ; do
      # grep dir name
      if echo "$line" | grep -q "$f" ; then
        dir="$line"
        continue
      fi
      echo setfacl $line '"'$dir'"'>>recovery_acl.sh
      # grep non def acl (for files)
      if echo "$line" | grep -q '\-m' ; then
        echo setfacl $line '"'$dir'"'/*>>recovery_acl.sh
      fi
    done < "acl"
    rm -f acl
    sed -i 's/134/\\/g' recovery_acl.sh
    sed -i 's/040/\ /g' recovery_acl.sh
    

    After execution of script, will creating another "recovery_acl.sh". Replace UTS on your domain. Errors like "No such file or directory" means that dir is empty.

提交回复
热议问题