Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7885757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:09:09+00:00 2026-06-03T05:09:09+00:00

I have a script which looks for a file using a regular expression. The

  • 0

I have a script which looks for a file using a regular expression. The code was the following:

find $dir | grep "$regex"

The script run a bit too slow and I want to optimise it. The search takes some time to perform and I would like to get better performance out of it. I’ve tried this attempt:

find $dir -regex ".*${regex}.*"

I was expecting slightly faster results as no extra process is created to parse the regular expression.

However the result was different and to my astonishment the command “find | grep” is faster than “find -regex” (although it takes more system time, as one would have expected)

I’ve timed this behaviour:

Find | grep result

real   0m12.467s
user   0m2.568s
sys    0m7.260s

Find -regex result

real   0m16.778s
user   0m6.772s
sys    0m6.380s

Do you have any idea why the find -regex solution is slower?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:09:10+00:00Added an answer on June 3, 2026 at 5:09 am

    Most likely because grep and its regex engine has been highly optimized over many years, since that’s its only purpose (“do one thing and do it well”). I don’t know what regex engine find uses, but it’s evidently not as highly refined as grep‘s, probably because it’s a less-often-used secondary feature.

    Also, if you are doing anything with this file list, you should really use a more whitespace-safe way of doing this. I don’t think grep can take null-delimited input (though it can output it), so you should use find [...] -regex [...] -print0 even though it’s slower.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that generates a csv file using the following code: header('Content-type:
I have an auto-generated file which looks something like this... static void do_SomeFunc1(void* parameter)
I have a script with which I POST data to a server using cURL.
I have an index.html file which looks like this (the rest is omitted), <ul
I have a Jamroot file which looks a bit like this; project foo ;
I have a script that I'd like to continue using, but it looks like
I am using Codeigntier and I have the following dropdown in my view file
I have a script which loops through a list of users (samaccountname): # Read
I have a Perl script which nests foreach loops as seen below. It takes
I have a couple of scripts for which the first part of them looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.