I'm trying to create a bash script that will be able to perform a find command to get the permissions and full path of every file/directory in a directory tree and create a file for each unique permission and printing each full file path to that permissions file. Then in the future I could read these files and use them to permissions to the way they were when I ran the script.
drwxrwxrwx /home/user/testDirectory -rwxrwxrwx /home/user/testDirectory/testFile drwxr-xr-x /home/user/testDirectory/directory2 -rwxr-xr-x /home/user/testDirectory/directory2/test2
The above would create 2 files (e.g.
755.txt) that would each have 2 of the lines.
I am struggling with the logic to create a file for each unique permission and then send the full file path.
What I have so far (I doubt the array is necessary, but I have played with sorting the array by permission which I can do with -k 1.2 on the sort command to ignore the d flag):
declare -a PERMS i=0 while read line do PERMS[$i]="$line" (( i++ )) done < <( find /opt/sas94 -printf ""%M/" "%p/"\n")