List all files not starting with a number

15,169

Solution 1

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

Solution 2

You don't need grep, just ls:

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

if you want to search the whole subdirectory structure use find:

find /proc/ -type f -regex "[^0-9]*" -print

Solution 3

Use grep with -v which tells it to print all lines not matching the pattern.

 ls /proc | grep -v '[0-9+]'

Solution 4

ls /proc | grep -v -E '[0-9]+'

Share:
15,169
Pavan Manjunath
Author by

Pavan Manjunath

Software Engineer @ Lyft, SF Bay Area

Updated on June 18, 2022

Comments

  • Pavan Manjunath
    Pavan Manjunath almost 2 years

    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!