Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell - How to deal with find -regex?

Tags:

regex

find

shell

I need to look in a directory for sub-directories that all start by "course" but they have version next. For example

course1.1.0.0
course1.2.0.0
course1.3.0.0

So how should I modify my command to make it give me the right list of directories?

find test -regex "[course*]" -type d
like image 385
Farah Avatar asked Nov 07 '13 15:11

Farah


1 Answers

You can do:

find test -type d -regex '.*/course[0-9.]*'

it will match files whose name is course plus an amount of numbers and dots.

For example:

$ ls course*
course1.23.0  course1.33.534.1  course1.a  course1.a.2
$ find test -type d -regex '.*course[0-9.]*'
test/course1.33.534.1
test/course1.23.0
like image 117
fedorqui 'SO stop harming' Avatar answered Sep 28 '22 06:09

fedorqui 'SO stop harming'