Last active
August 29, 2015 14:13
-
-
Save stephanb/3f02636bcf1fe9300b89 to your computer and use it in GitHub Desktop.
Rename and copy/move all files or directories matching a pattern
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
find . -type f -name "*your-pattern*" | while read oldname; do newname=`echo $oldname | sed 's/your-pattern/substitute-value/g'`; cp $oldname $newname; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This command:
your-pattern
in their filenames in the current directory and its sub-directoriesyour-pattern
withsubstitute-value
in the filenameReplace
your-pattern
andsubstitute-value
with your own values.If you want to rename the file rather than copy it, replace the command
cp
withmv
.If you want to work with directories only, use
-type d
instead of-type f
.