[SOLVED] find command match pattern

Hello,

I would like to ask you, how to match directory names. I need to find only directories, which are created only from numbers and doesn't include any letters.

I used command

find $AC_WORKDIR/work_archive/test/$dirs_years -maxdepth 1 -name \[0-9]\* -print

If I have dirs like
12
12ab
ab12

it gives dirs 12, 12ab. I need only dir 12. Thank you for your answer

The awk script below will print all directory names in or under $AC_WORKDIR/work_archive/test/$dirs_years with names that only contain digits. You can put back in the maxdepth clause if you only want directories in (not under) that directory. (Note, however, that -maxdepth is not required by the standards and is not present in all implementations of the find utility.)

find $AC_WORKDIR/work_archive/test/$dirs_years -type d ! -name '*[!0-9]*'

Try the below example:

$ cd tmp
$ ls -l
drwxr-xr-x+ 1 Sep 22 17:33 1
drwxr-xr-x+ 1 Sep 22 17:34 12
drwxr-xr-x+ 1 Sep 22 17:34 12ab
drwxr-xr-x+ 1 Sep 22 17:34 2
drwxr-xr-x+ 1 Sep 22 17:34 ab12
drwxr-xr-x+ 1 Aug 22 19:14 txt2regex-0.8

$ find . -maxdepth 1 -regex "./[0-9]*"
./1
./12
./2

Thank you for your help :b: