如何列出一个目录下的所有可执行文件

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
自由建客
帖子: 13468
注册时间: 2008-07-30 23:21
系统: Debian stable AMD64

如何列出一个目录下的所有可执行文件

#1

帖子 自由建客 » 2015-09-30 20:35

不跟踪软链接。
仅列文件名,不要 ls -l 那种长格式。
头像
susbarbatus
帖子: 2966
注册时间: 2010-04-10 16:14
系统: Arch Linux

Re: 如何列出一个目录下的所有可执行文件

#2

帖子 susbarbatus » 2015-09-30 20:55

笨办法:

代码: 全选

ls -l | egrep "^-[^ ]*x" | awk '{for(i=9;i<=NF;i++) {printf $i" "} printf "\n"}'
上次由 susbarbatus 在 2015-12-14 13:55,总共编辑 1 次。
沉迷将棋中……
头像
自由建客
帖子: 13468
注册时间: 2008-07-30 23:21
系统: Debian stable AMD64

Re: 如何列出一个目录下的所有可执行文件

#3

帖子 自由建客 » 2015-09-30 21:55

susbarbatus 写了:笨办法:

代码: 全选

ls -l | egrep "^-[^ ].*x" | awk '{for(i=9;i<=NF;i++) {printf $i" "} printf "\n"}'
:em20
还不如这样呢

代码: 全选

	cd "$Dir"
	for file in *
	do
		[ -f "$file" -a -x "$file" ] && echo "$file"
	done
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 如何列出一个目录下的所有可执行文件

#4

帖子 poloshiao » 2015-10-01 6:20

試試

代码: 全选

sudo ls -F | grep "*"
參見
http://manpages.ubuntu.com/manpages/viv ... /ls.1.html
-F, --classify
說明
上述指令列出來的檔案名稱 後面多了一個 "*"
標示 可執行 屬性
头像
susbarbatus
帖子: 2966
注册时间: 2010-04-10 16:14
系统: Arch Linux

Re: 如何列出一个目录下的所有可执行文件

#5

帖子 susbarbatus » 2015-10-01 10:20

自由建客 写了:
susbarbatus 写了:笨办法:

代码: 全选

ls -l | egrep "^-[^ ].*x" | awk '{for(i=9;i<=NF;i++) {printf $i" "} printf "\n"}'
:em20
还不如这样呢

代码: 全选

	cd "$Dir"
	for file in *
	do
		[ -f "$file" -a -x "$file" ] && echo "$file"
	done
啧啧啧…你不懂写成一行的美啊,管道才是男人浪漫 :Shame
沉迷将棋中……
头像
自由建客
帖子: 13468
注册时间: 2008-07-30 23:21
系统: Debian stable AMD64

Re: 如何列出一个目录下的所有可执行文件

#6

帖子 自由建客 » 2015-10-01 18:33

susbarbatus 写了:啧啧啧…你不懂写成一行的美啊,管道才是男人浪漫 :Shame

代码: 全选

cd "$Dir"; for file in *; do; [ -f "$file" -a -x "$file" ] && echo "$file"; done
头像
自由建客
帖子: 13468
注册时间: 2008-07-30 23:21
系统: Debian stable AMD64

Re: 如何列出一个目录下的所有可执行文件

#7

帖子 自由建客 » 2015-10-01 18:35

poloshiao 写了:試試

代码: 全选

sudo ls -F | grep "*"
參見
http://manpages.ubuntu.com/manpages/viv ... /ls.1.html
-F, --classify
說明
上述指令列出來的檔案名稱 後面多了一個 "*"
標示 可執行 屬性
嗯,其实交互式我一直用 -F 的。只是这里还要去掉星号,有些麻烦。
头像
YeLee
论坛版主
帖子: 26406
注册时间: 2008-08-13 8:48
系统: Fundu i64
来自: 东海硇州,一双管钥。
联系:

Re: 如何列出一个目录下的所有可执行文件

#8

帖子 YeLee » 2015-10-04 10:06

代码: 全选

find /bin -type f -perm -111
ls -F |sed -n '/\*$/'p |sed -e 's/*$//g' 
:Noting
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
zhangxiaofir
帖子: 53
注册时间: 2010-12-09 23:54

Re: 如何列出一个目录下的所有可执行文件

#9

帖子 zhangxiaofir » 2015-12-08 22:05

find / -type f -executable

代码: 全选

man find
-executable
              Matches files which are executable and directories which are searchable (in a file name  reso-
              lution  sense).   This takes into account access control lists and other permissions artefacts
              which the -perm test ignores.  This test makes use of the access(2) system call, and so can be
              fooled  by  NFS servers which do UID mapping (or root-squashing), since many systems implement
              access(2) in the client’s kernel and so cannot make use of the UID mapping information held on
              the server.  Because this test is based only on the result of the access(2) system call, there
              is no guarantee that a file for which this test succeeds can actually be executed.
回复