Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

is it possible to list all the ".php" files located into a direcotry and their octal permissions?

I would like to list them like this:

775 /folder/file.php
644 /folder/asd/file2.php
etc...
share|improve this question

2 Answers 2

up vote 2 down vote accepted
find /folder -name '*.php' -type f -print0 |
  perl -0 -lne 'printf "%o %s\n", (lstat $_)[2]&07777, $_'

See also this related question: Convert ls -l output format to chmod format.

-print0 is a GNU extension also supported by BSDs like OS/X. GNU find also has a -printf predicate which could display the mode, but that one has not been added to BSD's find.

(Tested on OS/X 10.8.4 and Debian 7 but should work on any system that has any version of perl and find -print0 which includes all GNU systems and all recent BSDs)

share|improve this answer
    
i launched this from iside my folder /htdocs but it doesn't works :( do you tryed by yourself? –  sbaaaang Jul 13 '13 at 10:47
1  
@sbaaaang did you replace /folder with the real path? If you run from inside the target folder, that will be .. –  terdon Jul 13 '13 at 12:31
find /some/path -type f -name "*.php" -exec sh -c 'stat -f "%p %N" "{}" | sed -E s/^.{3}//' \;

This is tested on OS X 10.8.4. The sed pipe just cuts the first 3 characters off the output (filetype). Looks like OS X stat doesn't support straight-up octal permission output.

share|improve this answer
    
That assumes filenames don't contain double quote, backslash, dollar, backtick or newline characters and runs one sed, one sh and one stat commands per file. –  Stéphane Chazelas Jul 13 '13 at 10:27
    
Yes, yes it does. I'm making the assumption that PHP files aren't likely to contain any of those characters. –  Mel Boyce Jul 13 '13 at 10:43
    
try stat -f "%OLp %N" file –  jsbillings Jul 13 '13 at 12:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.