Sometimes in desperation, to test if my problem is not the permission problem I do:

sudo chmod -R 777 mydir/

In most cases it does not helps, and now I have two problems ;)

Files inside mydir/ had different permissions and owners each, and now I need to restore them to the original state.

Is there any smart way to recursive restore the permissions, except creating a backup copy? E.g.

command_to_save_the_permissions_somewhere mydir/
chmod -R 777 mydir/
command_to_restore_the_permissions_from_somewhere mydir/

BTW, any tips on debugging permission issues?

1 Answer 1


There's an easy way to back up and restore permissions amd ownerships of a directory tree using the ACL tools. It works even if you don't have ACLs enabled on the filesystem.

getfacl -R >saved-permissions
setfacl --restore=saved-permissions

Most permission issues will cause a “permission denied” error message to appear somewhere, either on the console or in some log file.

A powerful tool to investigate file access issues is strace. It shows the system calls made by a process. The output can be difficult to understand, but it's relatively easy to see what files the program is trying to access and why it can or cannot find what it wants. Usage examples:

strace -s9999 -o myprogram.strace myprogram  # trace myprogram
strace -s9999 -fF ...                        # also trace subprocesses
strace -s9999 -p12345                        # connect to running process by PID
strace -s9999 -efile ...                     # only show filesystem calls
strace -eaccess,open,stat,lstat              # only show common file access calls

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .