0

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.

1

-regex matches the whole path:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.