[英]Getting the names of the first n files without listing all of them in linux
[英]Listing files with numeric names
如何列出仅具有数字名称的文件,例如
1111
2342
763
71
我已经尝试过ls -l [0-9]*
但是这似乎带来了所有以数字开头的文件名,并且文件名后面可以有任何东西。
使用GNU find
:
find . -type f -regex './[0-9]*$'
这使用正则表达式而不是文件名遍历模式。 表达式./[0-9]*$
匹配./
(当前目录),后跟仅数字,直到末尾( $
)。
如果您需要停止find
子目录,请添加-maxdepth 1
。
如果您想要ls -l
-like行为,请在最后添加-ls
。
使用相反的操作:忽略非数字 [^0-9]
文件名:
ls -1 --ignore=*[^0-9]*
--ignore =模式
不列出与shell PATTERN匹配的隐式条目
此命令将永远是最安全的选择!
ls | grep -E '^[0-9]+$'
增加一些样本测试用例,以使读者清楚。
$ls
1 12222e 2 B.class Test.java file.sh y.csv
1.txt 1a A.class Test.class db_2017-08-15 file.txt
$ ls | grep -E '^[0-9]+$'
1
2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.