Skip to content

Instantly share code, notes, and snippets.

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

Assume have a directory of files in an 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:

    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 '{}' \;
  4. cleanup:

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