列出所有不以数字开头的文件 [英] List all files not starting with a number
问题描述
我想检查/proc
中存在的所有密钥文件.但是/proc
具有与正在运行的进程相对应的无数目录.我不想列出这些目录.所有这些目录的名称仅包含数字.由于我的正则表达式很差,所以谁能告诉我要发送给ls
的regex
使其变为 NOT ( NOT )的功能?
I want to examine the all the key files present in my /proc
. But /proc
has innumerable directories corresponding to the running processes. I don't want these directories to be listed. All these directories' names contain only numbers. As I am poor in regular expressions, can anyone tell me whats the regex
that I need to send to ls
to make it NOT to search files/directories which have numbers in their name?
更新:感谢所有答复!但是我很想拥有一个单独的ls
解决方案,而不是ls+grep
解决方案.到目前为止,仅提供的ls
解决方案似乎无效!
UPDATE: Thanks to all the replies! But I would love to have a ls
alone solution instead of ls+grep
solution. The ls
alone solutions offered till now doesn't seem to be working!
推荐答案
/proc
中所有不包含数字的文件和目录(换句话说,不包括进程目录):
All files and directories in /proc
which do not contain numbers (in other words, excluding process directories):
ls -d /proc/[^0-9]*
/proc
下所有以数字开头的文件都是递归的:
All files recursively under /proc
which do not start with a number:
find /proc -regex '.*/[0-9].*' -prune -o -print
但是这还将排除子目录中的数字文件(例如/proc/foo/bar/123
).如果您只想排除带数字的顶级文件:
But this will also exclude numeric files in subdirectories (for example /proc/foo/bar/123
). If you want to exclude only the top-level files with a number:
find /proc -regex '/proc/[0-9].*' -prune -o -print
再次坚持!这是否意味着将排除由touch /proc/123
等创建的任何常规文件?从理论上讲是可以的,但是我认为您不能做到这一点.尝试为不存在的PID创建文件:
Hold on again! Doesn't this mean that any regular files created by touch /proc/123
or the like will be excluded? Theoretically yes, but I don't think you can do that. Try creating a file for a PID which does not exist:
$ sudo touch /proc/123
touch: cannot touch `/proc/123': No such file or directory
这篇关于列出所有不以数字开头的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!