我有一个目录,其中包含一堆.zip文件以及它们的解压缩版本.我需要获取所有目录的列表并忽略.zip文件.我怎样才能做到这一点?
我正在考虑使用grep和ls,但我不确定如何将它组合在一起.
获取所有子目录的列表并将其存储到数组中:
shopt -s nullglob
dirs=( */ )
Run Code Online (Sandbox Code Playgroud)
如果你可以这样打开extglob:
shopt -s extglob
declare -a files=( !(*.zip) )
Run Code Online (Sandbox Code Playgroud)
在Pattern Matching手册页上查看有关bash模式匹配的更多信息.