Specific file name search

Hello i am new with UNIX and needed help with my search. I need to find a file that starts with 'f' than has unknown number of numbers then has 'gr' and ends with large letters also unknown number and unknown extension. ex. f123456grKNI, f11223grKE

Thank you up front :smiley:

Search where? In the directory that is your current working directory? In a file hierarchy rooted in your current directory? On the entire system that you're currently logged in to? On a network? Something else???

Can the unknown number of numbers following the leading 'f' be zero?

If you are just looking for one file, what should happen if there is more than one file that meets your criteria?

What operating system and shell are you using?

What have you tried to solve this on your own?

Hello,

On my test environment (Linux with GNU userland), something like this would appear to do what you need:

$ pwd
/home/unixforum/279952
$ ls 
f123456grKNI  foo/
$ ls foo
f11223grKE
$ find /home/unixforum/279952 -regextype posix-egrep -regex ".*f[0-9]{1,}gr*.*"
/home/unixforum/279952/foo/f11223grKE
/home/unixforum/279952/f123456grKNI
$ 

So the idea is to use GNU find , with the -regextype and -regex flags, to search for things that match your precise pattern, with that pattern defined as an egrep -compatible regex.

To be specific, our pattern matches things the name of which starts with a single 'f', is followed by one or more digits, the letters 'gr', and then none or more of anything else at all before the end of the name.

Hope this helps. If it doesn't quite work then if you can let me know where it falls down we can take things from there.