I'm trying to replace the word "owner" with "user" in all file names of my directory (and in all subdirectories).
Ex.
owners_controller => users_controller
owner.rb => user.rb
Any help would be appreciated
I'm trying to replace the word "owner" with "user" in all file names of my directory (and in all subdirectories).
Ex.
owners_controller => users_controller
owner.rb => user.rb
Any help would be appreciated
If you don't have
rename
installed, this should be a reasonable alternative (assumingbash
as your shell):Use
find
with the-exec
option to callrename
on every file and subdirectory containing "owner" in its name:If you don't have
rename
, you can use amv
command withbash
parameter expansion:bash -c '...'
invokes the bash shell on the one-liner surrounded by single-quotes. The one-liner acts as amv
command that renames all occurrences of "owner" in the basename of the matching filename/subdirectory to "user".Specifically,
find
substitutes every{}
after the-exec
with the matching file/subdirectory's pathname. Heremv
accepts two arguments; the first is{}
(described previously), and the second is a string returned from a sub-shell$(...)
containing three bash commands. These bash commands use parameter expansion techniques to rename the basename of{}
.