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 8467391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:37:50+00:00 2026-06-10T15:37:50+00:00

I am building a find command programatically: find ${SRC_DIR} ${FILE_NAMES} -type f -mtime +14

  • 0

I am building a find command programatically:

find  "${SRC_DIR}" "${FILE_NAMES}" -type f -mtime +14 -level 0

Where FILE_NAMES is the file patterns that I need to match, which is a simple whitespace delimited list of patterns (*.txt, *.html, etc).

To format this list correctly for the find command, it can’t just be a list though, it has to look like:

-name *.txt -o -name *.html

My solution was to use:

FILE_NAMES=$(echo ${FILES} | sed -e 's/\s+/-o -name /g')

But it’s not working, specifically it doesn’t seem to understand that I want to replace whitespace. Does anyone have a better way to do this?

  • 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-10T15:37:52+00:00Added an answer on June 10, 2026 at 3:37 pm

    Not all seds support perl-like place holders for space, digits, etc. I don’t have a way to test your exact case, but the following should be a good guide.

    Also, note that find -predicate -predicate .... are ANDed by default. to make the -o work, you have to surrond the whole thing in ( (parens) ) AND so the shell won’t see the paren as a request to launch a subshell, you have to escape the parens, i.e \( .... -o .... \). So that leads us to

     set -vx; SRC_DIR="." ; FILE_NAMES="a b c"
     find  "${SRC_DIR}" \( $(echo "$FILE_NAMES"| sed 's/ / -o -name /g;s/^/-name /') \) -type f -mtime +14 -level 0
    

    OUTPUT

    + echo 'a b c'
    + sed 's/ / -o -name /g;s/^/-name /'
    + find . '\( -name a -o -name b  -o -name c \)' -type f -mtime +14 -level 0
    find: invalid predicate `-level'
    

    which just indicates that my find doesn’t support -level either.

    edit removed extra " chars surounding the \(....\).

    also

    If you’re using a ksh93, it maybe possible to use variable modifiers, like

    ${FILE_NAME// / -o -name}
    

    But you’ll need to either just concatenate the opening -name or do a 2nd substitution on the saved value of FILE_NAME.

    You can see if you have ksh93 by issuing the following cmd

    echo ${.sh.version}
    

    If you get a value, then you have ksh93.

    IHTH

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

Sidebar

Related Questions

In Android (after building), we find in the bin folder a file of extension
I am building a custom admin extension, I need to find a user's role
I am building a tool that will iterate though files to find function names.
I am building a Music file organizer(in python2) in which I read the metadata
I'm building a page that will allow a user to upload an MP3 file.
Im building a calendar and to find out the first day of the month
I am building an application to find the route between two places.Also, i have
I Keep building projects and then have to do a find and replace for
How do I find out what platform SCons is building for (Linux, Mac OS
I am building my own home page. I find someone's page good, and downloaded

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.