linux 中的可执行文件使用(perm)?

executable files in linux using (perm)?

我正在尝试写出 /etc 目录下所有其他用户可执行且名称以数字开头或结尾的所有内容的名称列表。

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

但是每次我都答错了,你能帮忙吗?

如果您正在使用 zsh shell,您可以获得该文件列表及其高级 filename generation globbing;无需外部程序。特别是,使用 递归 glob、交替和匹配世界可执行文件的 glob 限定符

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

首先执行 setopt glob_dots 以匹配以 . 开头的文件名。就像 find 一样。否则他们会被跳过。


如果您使用 find,您需要 -perm 到 select 文件的 -mode 参数至少具有给定的权限位(这实际上是什么你有你的问题并且对我有用)

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