1

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 2

2

-regex matches the whole path:

find /path -type d -regex ".*/[0-9.]+"
5
  • But doesn't it allows letters on other positions? Nov 12, 2017 at 15:11
  • 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.
    – dessert
    Nov 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
  • Sorry, I've eddited last comment :) Nov 12, 2017 at 15:32
  • Your code is working, don't know why in first place it didn't worked Nov 12, 2017 at 16:15
0

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 ..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .