在我的文件夹中,我得到了类似的文件
/data/filename.log /data/filename.log.1 /data/filename.log.2 /data/filenamefilenamefilename.log /data/filenamefilenamefilename.log.2
我希望使用“查找”命令列出长度大于 15 个字符的文件。
我尝试了以下方法,但它们都不起作用:
find ./ -type f -iregex "/^.*{15,1000}$/" -print
find ./ -type f -iregex "/^.*{15}$/" -print
find ./ -type f -iregex "^.*{15}$" -print
find ./ -type f -iregex ".*{15}" -print
find ./ -type f -iregex ".{15}" -print
find ./ -type f -iregex ".{15,1000}" -print
Run Code Online (Sandbox Code Playgroud)
不知道正确的方法是什么?
谢谢!
该name参数接受简单的通配符,因此以下将起作用:
find . -type f -name '????????????????*'
Run Code Online (Sandbox Code Playgroud)
所以这是 16 个问号,后跟一个星号。问号匹配单个字符,但必须匹配,因此连续 16 个问号确保文件名中有 16 个字符。末尾的星号允许任何附加字符,通过匹配“16 个或更多字符”来满足“大于 15 个字符”的要求。
如果您只想匹配文件名,我建议使用 Paul 的版本。如果你想-regex在完整路径上使用匹配,你可以这样做
find /data -type f -regextype posix-egrep -regex ".{15}"
Run Code Online (Sandbox Code Playgroud)
或 15 个或更多字符
find /data -type f -regextype posix-egrep -regex ".{15}.*"
Run Code Online (Sandbox Code Playgroud)
检查手册页以了解可与 一起使用的不同可用正则表达式引擎-regextype。
您还可以使用该-regex选项仅查找 15 个字符的文件名:
find /data -type f -regextype posix-egrep -regex ".*/[^/]{15}"
Run Code Online (Sandbox Code Playgroud)
或 15 个或更多字符:
find /data -type f -regextype posix-egrep -regex ".*[^/]{15}"
Run Code Online (Sandbox Code Playgroud)