Trying to write -regex
for a find
statement that shows only directories with dots and numbers, for example 1.2.3.4 oraz 1.2.3 or 1.3.4.5.6 was trying something like "-regex '\.[0-9.]+'"
, but it also shows dirs with letters. And I only want directories with numbers and dots.
2 Answers
-regex
matches the whole path:
find /path -type d -regex ".*/[0-9.]+"
-
-
You mean inside the path? Yes, this will find any directory which has only
[0-9.]
in its name, regardless of the path. If you want to match[0-9.]
in the whole path use-regex "[0-9./]+"
instead.– dessertNov 12, 2017 at 15:14 -
It's like, I have directory which contains other directories for example something.txt something2.txt 1.2.3.4 5.6.8 4.3.2 and I want to show only those which contains only numbers and dots But both answers show's me also directories with characters... Nov 12, 2017 at 15:30
-
-
Your code is working, don't know why in first place it didn't worked Nov 12, 2017 at 16:15
Standardly:
LC_ALL=C find /path ! -name '*[!0-9.]*' -type d
That is, list files of type directory whose name doesn't not contain a character other than decimal digit or .
.