1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Use grep to find files matching several file types that contain certain phrasses

Discussion in 'Site & Server Administration' started by postcd, Dec 31, 2015.

  1. #1
    Hello dear members,

    im having linux bash script to search around 30 pathes for files that contains phrasses from my phrasses file. This is the command used:

    /bin/nice -n 19 grep -sRil "$phrasse" /home/$foldername/public_html >> filesmatchingphrasses

    There is quite big amount of phrasses and foldernames and search is done thru many files so i would like to allow grep (or any other linux command?) to examine only files of around 5 certain file types. Example: .php, .htm, .html

    I wanted to ask how can i modiffy my command? Or is there any command that is less intensive on server resources?

    ----
    there is "find" alternative command, but i wish i use grep as i think find somehow did not worked properly to output files matching phrasses.

    there is an simply looking grep command but im little bit afraid to run it so it do not cause anything bad

    there appears to be good ideas for both grep and find

    Should i just add:
    --include=*.{html,php,htm}
    into my command? i added it after "-sRil" part and it appears to work
     
    Last edited: Dec 31, 2015
    postcd, Dec 31, 2015 IP
  2. bjdea1

    bjdea1 Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Xargs should help, something like this should do it:

    find /home/$foldername/public_html -type f -name '*.php' -or -name '*.htm' -or -name '*.html' | xargs grep "$phrasse" >> filesmatchingphrasses
     
    bjdea1, Jan 25, 2016 IP