使用特定的字符串在我的PATH中查找可执行文件 [英] find executables in my PATH with a particular string
问题描述
有没有一种方法可以快速知道我的 $ PATH
中的可执行文件是否包含特定的字符串?例如,我要快速列出包含 SRA
的可执行文件.
Is there a way to quickly know whether an executable in my $PATH
contains a particular string? For instance, I want to quickly list the executables that contain SRA
.
我问的原因是我有几个脚本,其中包含字符 SRA
.问题是我总是忘记文件的起始字符(如果我还记得的话,我会使用制表符补全来找到它).
The reason I'm asking is that I have several scripts with the characters SRA
in them. The problem is that I always forget the starting character of the file (if I do remember, I use tab completion to find it).
推荐答案
您可以将所有路径存储在数组中,然后使用 find
及其各种选项:
You can store all the paths in an array and then use find
with its various options:
IFS=":" read -ra paths <<< "$PATH"
find "${paths[@]}" -type f -executable -name '*SRA*'
-
IFS ="::"读取-ra路径<<<"$ PATH"
将所有路径读入数组,将字段分隔符临时设置为:
,如源). IFS=":" read -ra paths <<< "$PATH"
reads all the paths into an array, setting the field separator temporarily to:
, as seen in Setting IFS for a single statement.-type f
looks for files.-executable
looks for files that are executable. You may use-perm +111
instead in OSX (source).
由于 -executable
选项在FreeBSD或OSX中不可用,因此
Since the -executable
option is not available in FreeBSD or OSX, ghoti nicely recommends to use the -perm
option:
find -perm -o=x,-g=x,-u=x
这篇关于使用特定的字符串在我的PATH中查找可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!