find and replace a word with another in all file names of a directory

后端 未结 2 574
广开言路
广开言路 2021-01-27 12:37

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_         


        
2条回答
  •  悲哀的现实
    2021-01-27 13:13

    If you don't have rename installed, this should be a reasonable alternative (assuming bash as your shell):

    while read entry
    do
      mv "${entry}" "${entry/owner/user}"
    done < <(find . -depth -name '*owner*' -print)
    

提交回复
热议问题