Linux – How to check file permissions via SSH

linuxshellssh

To start out I am very new to this so please forgive me if this is extremely basic or I sound overly uninformed.

I would like to check all the files in a specific directory on my VPS to ensure that files are 644 and directories are 755. FTP is out of the question because there are far too many files/directories. SSH seems the most logical choice, but before i go chmod permissions I'd like to see what I'll be changing. Is there any way to find and display files/directories that do not meet this criteria?

Thanks in advance for any insight.

Best Answer

As a refinement to David Spillett's answer, how about using a single find command? I think it's a bit cleaner than all the pipes, and calls to grep. Furthemore, it cuts out a bit of the edge cases where this might blow up.

find . -type f ! -perm 644 should find every file that doesn't have -rw-r--r-- permissions. For directories, you can use find . -type d ! -perm 755.

Once you're happy with what you're seeing, you can even combine the chmod into the same command:

find . -type f ! -perm 644 -exec chmod 644 {} \;
find . -type d ! -perm 755 -exec chmod 755 {} \;