4

I need a regex expression to use along with find to find all the files which name start with a given string, for example proc.

I tried with find . -regex '^proc*' but it gives me no results.

1
  • I have another regex expression which finds me all the files with certain extensions .*\.(c|h|txt), and under one condition in my script I plan to join these two patterns together.
    – Dandry
    Commented Oct 21, 2016 at 19:30

2 Answers 2

9

It would be better to use just the -name 'proc*' in this case, which uses globbing, and searches through the filename only (unlike -regex which searches through the whole directory entries leading to the filename).

If you insist on using -regex, leveraging greediness:

find . -type f -regex '.*/proc[^/]*$'
0
3

You don't need the regex flag

$ find . -type f -name "proc*"
2
  • 2
    The question is valid 'how to use -regex' answering with "don't" is not helpful.
    – Jay M
    Commented Nov 25, 2022 at 11:14
  • @JayM OP is asking how to find files where name starts with a given string. This answer is just pointing out that he can achieve that without the need of using regex option.
    – tachomi
    Commented Nov 29, 2022 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .