Skip to content

Instantly share code, notes, and snippets.

@tomsaleeba
Last active May 18, 2018
Embed
What would you like to do?
Bulk file rename

Assume have a directory of files in an Angular.io project. We need to clone them all but rename and do a find+replace in them to work with another model name. The old model is plot and the new model is photo.

  1. Clone the directory and contents

    cp -r plot photo
    cd photo
  2. create a script to receive the results from our find:

    # blah.sh
    orig=$1
    new=`bash -c "echo $orig | sed 's/plot/photo/'"`
    mv $orig $new
    find . -type f -name '*photo*' -exec sed -i 's/plot/photo/g' '{}' \;
    find . -type f -name '*photo*' -exec sed -i 's/Plot/Photo/g' '{}' \;
  3. do the find:

    find . -type f -name '*plot*' -exec bash blah.sh '{}' \;
  4. cleanup:

    rm blah.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment