我想知道是否有办法指定 zsh 中给定目录下的前 N 个文件。
我对递归枚举(即路径下递归的任何文件都被考虑用于枚举)和非递归(只考虑那些严格位于给定文件夹下的文件)的解决方案感兴趣。
谢谢!
Gil*_*il' 11
它是 zsh,所以确实有一个glob 限定符。
echo *([1,42]) # The first 42 files in the current directory, in lexicographic order
echo **/*([1,42]) # The first 42 files in a depth-first traversal
echo **/*(od[1,42]) # The first 42 files in a breadth-first traversal
Run Code Online (Sandbox Code Playgroud)
其他可能有用的限定符,例如以下表达式包括点文件 ( D)、限制到常规文件 ( .) 和符号链接 ( -) 到常规文件,如果没有匹配项 ( N)则扩展为空列表:
echo *(-.DN[1,42])
Run Code Online (Sandbox Code Playgroud)