仅列出与通配符表达式匹配的文件夹

List only folders which matches the wildcard expression

是否有一个命令可以列出与通配符表达式匹配的所有文件夹?例如,如果有数千个目录,而我只想列出以 M 结尾或以 JO 开头的目录,我可以使用某个 Linux 命令来实现吗?谢谢!

使用find命令,例如:

# find anything that start with 'jo' end with 'm' (case insensitive)
find . -iname 'jo*m'

之后可以执行任意命令,例如:

# find just like above but case sensitive, and move them to `/tmp`
find . -name 'JO*M' -exec mv -v {} /tmp \;

只查找一个目录,可以使用-type d标志,例如:

# find any directory that start with JO
find . -name 'JO*' -type d

说明,第一个参数是起始目录,.表示当前目录。下一个参数表示搜索条件 -name 用于区分大小写的搜索,-iname 用于不区分大小写的搜索,-type 用于项目搜索的类型,-exec 用于执行某些命令,其中 {}是匹配的文件名。您可以了解更多 here or for your specific case here.