Another method is using perl...
Code:
perl -e 'printf "%o\n", (stat(shift))[2];' ~
40755
the '40000' means it is a directory. Note you need to print in Octal!
I wrote a script that reads a separate meta file to ensure my whole home has correct permissions depending on location (public or private), executable status, and allow me to say things like
bin/ -- all executable files
bin/admin/ -- private executable scripts
bin/admin/*.template -- non-executable data for a mailing script
Though the data in my permission file looks like...
Code:
# DIRS EXEC DATA
bin/ 755 755 644 R
bin/admin/ 700 700 700
bin/admin/*.template 600
The columns are direction, executable, datafile permissions and 'R' mean recurse into deeper sub-directories (directory, which end in '/', specifications only).
My permissions script "do_perms" has works for me for years, though I am looking for a better program, or improvements that would allow me to specify specific what files I am refering to better, without me needing to specify EVERY file.