How to save directory and file permissions before you CHOWN them to something else

There are times when you need to fix a website or user’s file permissions all at once using the CHOWN command.

e.g.

CHOWN -R someuser:someuser * (for all files recursive into all sub-directories)

 

or

 

CHOWN -R someuser:someuser some-directory (for all files recursive starting at the directory named “some-directory”

 

Usually this is the case in which a directory structure or website is so messed up with a mix of file permissions and ownership.

You may also want to do this for file permissions instead of file ownership. In that case you would be setting this up before you did a CHMOD of the files.

The command you want to use is called suphpfix. You would need to make sure this is installed on your server. In most cases it should already be installed. You can find the website for this command here.

Step to take:

Before you make any CHMOD or CHOWN changes to files or directories type:

suphpfix –save-state $cpuser

 

After you change files permisisons or ownership – if you need to restore the permissions for that user, you can type:

suphpfix –restore-state $cpuser

That is it! This is a very handy way to preserve the file and directory permissions for a user so you have an easy way to roll things back.

Want to discuss a project?

  • This field is for validation purposes and should be left unchanged.