Find and Replace Filenames
Command Line, Linux, Sysadmin
This might be needed when starting a project by cloning a scaffold boilerplate from Github (e.g. the WordPress boilerplate plugin).
TODO Build a BASH script to scaffold projects with automatic renaming of files.
Rename filenames in WP Plugin Boilerplate
Rename files and directories recursively. Run from the project root:
Options
- The
.
runs the find command recursively in the current directory - in this case it finds all files & directories - The -exec argument executes rename for every matching file found - all files.
'{}'
is replaced with the path name of the file.\;
marks the end of the exec expression.- The
-n
option on rename runs the command in “no act” mode.
The substitution takes the form s/target/replacement/[gi]
, where:
target
is the string to be replacedreplacement
is the replacing string
The g
option is for ‘global’ action - all instances are replaced.
An i
denotes a case insensitive rename.
Examples
Find .jpg files with the string ‘holiday’ in the filename, replacing this with ‘vacation’:
Resources
comments powered by Disqus