Skip to content

Instantly share code, notes, and snippets.

@branquito
Created March 1, 2013 00:19
Show Gist options
  • Save branquito/5061382 to your computer and use it in GitHub Desktop.
Save branquito/5061382 to your computer and use it in GitHub Desktop.
batch rename files or folders recursively in bash
command to find recursively files {can be modified for folders too, change -type f}, and renamed them by specfying regex pattern
find . -type f -maxdepth [depth] -name "[filepattern]" | while read FNAME; do mv "$FNAME" "${FNAME//search/replace}"; done
example:
find . -type f -maxdepth 1 -name "domain*.php" | while read FNAME; do mv "$FNAME" "${FNAME//domain/lead}"; done
before: after:
domains.php leads.php
domain.php lead.php
to do same for folders just change -type f --> -type d
@branquito
Copy link
Author

@joselcvarela you're welcome!

@kentarofujiy
Copy link

cheers mate!

@fabriciocybershell
Copy link

fabriciocybershell commented Sep 28, 2020

the find command argument is reversed, it does not accept global commands before the other parameters, correction: find. -maxdepth [depth] -type f -name "[filepattern]" ...
it may be a question of some version or the options selected in [depth]

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