Find the answer to your Linux question:
Results 1 to 4 of 4
This script: find $wheretosearch -type f -mmin -90 -size -1200k -iname '*.php' -iname '*. js ' -exec grep -l "$phrasse" {} \; >> $outputfile Is the order of parameters correct? ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User postcd's Avatar
    Join Date
    Apr 2011
    Posts
    333

    How to optimise "find" command, order of parameters


    This script:
    find $wheretosearch -type f -mmin -90 -size -1200k -iname '*.php' -iname '*.js' -exec grep -l "$phrasse" {} \; >> $outputfile

    Is the order of parameters correct? and are there any better alternatives to achieve my command (less resource usage)?

    Im especially not sure about this part:
    -iname '*.php' -iname '*.js'

    thx
    Last edited by postcd; 02-06-2014 at 09:46 AM.

  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    947
    Must be more to the script that initialize the variables. Taking a look the -mmin your parameter is -90 would it be 90 for 90 minutes. Also -size you have -1200k wouldn't the be -size k1200. Try from the command like it didn't like -iname '*.php' -iname '*.js'. It seens on only want a single -iname.

    Did you test this from the command line before using in a script, I find it save me time to workout command from CLI first then put them in scripts.

  3. #3
    Linux User postcd's Avatar
    Join Date
    Apr 2011
    Posts
    333
    Yes, the script is doing what i want, finding files containing certain phrasse, file must be younder 1,5 hour and smaller than 1,2MB.

    But: -iname '*.php' -iname '*.js'

    this fails and make the script buggy

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    947
    Quote Originally Posted by postcd View Post
    Yes, the script is doing what i want, finding files containing certain phrasse, file must be younder 1,5 hour and smaller than 1,2MB.

    But: -iname '*.php' -iname '*.js'

    this fails and make the script buggy
    That's what I noted it only accepts a single -iname. Easy fix would be just make each extention as separate line in the script.
    I guess the name matching would support RE so could create a RE pattern to match either extentions.
    Last edited by docbop; 02-07-2014 at 04:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •