Question

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!

Was it helpful?

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

OTHER TIPS

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

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

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

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

Following regex matches all the characters except numbers

^[\D]+?$

Hope it helps !

For the sake of of completion. You may apply Mithandir's answer with find.

  find . -name "[^0-9]*" -type f
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top