How to change all occurrences of a word in all files in a directory

后端 未结 4 1824
感动是毒
感动是毒 2020-12-13 02:52

I was in the process of creating a User class where one of the methods was get_privileges();.

After hours of slamming my head into the keyb

4条回答
  •  攒了一身酷
    2020-12-13 03:15

    for Mac OS:

    find . -type f -name '*.sql' -exec sed -i '' s/privelages/privileges/ {} +
    

    Matwilso's script from above would then look like this if it were designed to work on Mac OS

    #!/bin/bash
    
    # This will replace all instances of a string in folder names, filenames,
    # and within files.  Sometimes you have to run it twice, if directory names change.
    
    
    # Example usage:
    # replace_string apple banana
    
    echo ${1}
    echo ${2}
    
    find . -type f -name '*.sql' -exec sed -i '' s/${1}/${2}/ {} + # inside sql scripts
    

提交回复
热议问题