Search code examples
regexlinuxshellls

List all files not starting with a number


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?

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!


Solution

  • All files and directories in /proc which do not contain numbers (in other words, excluding process directories):

    ls -d /proc/[^0-9]*
    

    All files recursively under /proc which do not start with a number:

    find /proc -regex '.*/[0-9].*' -prune -o -print
    

    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
    

    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