Home > Blockchain >  executable files in linux using (perm)?
executable files in linux using (perm)?

Time:10-18

i'm trying to write out a list of the names of everything under the /etc directory that are executable to all other users and whose name starts or ends with a number.

find /etc "(" -name "[0-9]*" -o -name "*[0-9]" ")" -perm -o=x -print 

But every time I get a wrong answer, can you help?

CodePudding user response:

If you're using the zsh shell, you can get that list of files with its advanced filename generation globbing; no external programs needed. In particular, using a recursive glob, alternation, and a glob qualifier that matches world-executable files:

zsh$ printf "%s\n" /etc/**/([0-9]*|*[0-9])(X)
/etc/alternatives/animate-im6
/etc/alternatives/c89
/etc/alternatives/c99
/etc/alternatives/compare-im6
/etc/alternatives/composite-im6
...
/etc/X11
/etc/X11/fonts/Type1
/etc/xdg/xdg-xubuntu/xfce4
/etc/xdg/xfce4
/etc/xfce4

Do a setopt glob_dots first to match filenames starting with . like find does. Otherwise they get skipped.


If you're using find, you need the -mode argument to -perm to select files with at least the given permission bits (Which is actually what you have in your question and works for me)

find /etc \( -name "[0-9]*" -o -name "*[0-9]" \) -perm -o=x
  • Related