Created
March 1, 2013 00:19
-
-
Save branquito/5061382 to your computer and use it in GitHub Desktop.
batch rename files or folders recursively in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
@joselcvarela you're welcome!
cheers mate!
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
@larmoe you're welcome, glad it helped