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.

I looked into the find command and came up with find . -maxdepth 1 -perm 521 > test.txt to output the permissions to a text file, but is it possible to do it just using, for example, simple commands like ls? As far as I know, ls can't seem to reference permissions specifically so I can't give it a certain permission set to look for.

Is there any other straightforward method I may be overlooking?

share|improve this question
3  
What is un-simple about find? It is a bog-standard Unix command. –  vonbrand Jan 30 '13 at 21:50
add comment

3 Answers 3

Perhaps, you are searching something like:

ls -l | grep '^.r-x-w-r--'

IMHO, there is no tool better than find to search files. It is simple, straightforward and very powerful. Using find ... -exec ... or find ... -print0 | xargs -0 ..., you can easily manipulate, in many ways, files you find. I do not think that you can find any better general purpose tool.

share|improve this answer
add comment

If you don't like find you might use standard tools like stat and awk as follows:

shopt -s dotglob
awk '/^521/ {print $2}' <(stat -c "%a %n" *) > test.txt

You need to set the dotglob option if hidden files should be included in the expansion of *.

share|improve this answer
add comment

find is the straightforward method. If you use zsh, you can use its glob qualifier f (or a bunch of other qualifiers to characterise permission bits individually).

echo *(f521)
share|improve this answer
add comment

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.