2

So in my Systems Programming class, we were asked a question on how to search for all file names that are seven letters long, start with 'F' and the fifth letter is 'o'. I'm confused as to how to properly do this. I assume it involves the use of find and a combination of regular expressions. I've tried to use similar syntax to grep, but I'm having no luck at all. If anyone could help me formulate proper syntax to list all files that follow the pattern above, it would be greatly appreciated!

The direction I was heading:

find . -name [this is what I need help with] -type file
whoan
  • 8,143
  • 4
  • 39
  • 48

1 Answers1

0

There are many approaches. You can use

find ./ -regex ".*/F...o..$" -type f

but find apply regex to full relative path to the file, not just the file name itself, and you need to write your regex accordingly (this is why I match .*/ before file name itself). Also output will contain realtive path to the file.

or you can list only file names without path (each on separate line) with find and pipe output to grep:

find . -type f -printf "%f\n" | grep -e "^F...o..$"
Ján Stibila
  • 619
  • 3
  • 12