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
Here's an example for easily doing this with a single file. No additional tools, scripts, temp file, etc. are required. You could expand upon this method for working with more files if needed.
In this specific example, the permissions are saved in a varibale via the stat command. Then, the file is temporarily stripped of any restrictive permissions. Next, something is done with it (that may have failed due to those prior restrictions). Finally, the original permissions are restored.
file=$1
saved_permissions=$(sudo stat -c %a $file)
sudo chmod 777 $file
#
sudo chmod $saved_permissions $file