• PRODUCT

    PRODUCT

  • PRICING
    PRICING

  • HELP
    HELP

  • BLOG
    BLOG

  • APPSTORE
    APPSTORE

  • COMPANY
    COMPANY

  • LEGAL
    LEGAL

  • LOGIN
    LOGIN

  • Using unix find utility to recursively look into specific extensions for specific content excluding node-modules


  • It can get tricky to recursively look for specific text in the files that you care about in the locations that you care about. We will show you how.


  • The general syntax is:

    find . \( -name node_modules -prune \) -o -iname "filenamewildcard*" -type f -exec grep -i -H "wordmatch1\|wordmatch2" {} \;

    The output can be quite big, so if you are only interested in seeing the unique filename hits you should pipe the output through the following:

    cut -d":" -f1 | sort -u

    Bulk String Replace in Files

    While sed is probably the most popular tool that is used, it gets tricky when using bulk search/replace using find. The following is the suggested method:

    create a script called replace.sh with the following content:

    cat $1 | sed 's/stringtosearch/replacement/g' > ../$1

    mv ../$1 $1

    you can then use find to launch the script:

    find . -iname "files" -exec ./replace.sh {} \;

    SED can behavace unexpectedly for doing the changes in palce with the filename.

    Get rid of ^M in text files

    This can happen when you work in a mixed environment. To fix this, you should convert DOS line endings to Linux line endings. For example using vim:

    set ff=unix

    %s/\r//g

    As a side note, if you are using Visual Studio, please be sure to use .editorconfig at the solution root with the following:

    endofline = lf


  • Izyware Blog
    Izyware Blog