There are multiple texts with the name
Hoge in the directory
Here, I want to replace both the directory name and the file name with
find `pwd` -name "*Hoge*" -print | perl -nle 'rename $_, s|Hoge|hoge|r'
At this point, a list of target directories and files will appear.
I don't use
-print0 because I want perl to process each line.
% find `pwd` -name "*Hoge*" -print /Users/omokawayasuaki/test/Hoge /Users/omokawayasuaki/test/Hoge/Hoge1.txt /Users/omokawayasuaki/test/Hoge/Hoge3.txt /Users/omokawayasuaki/test/Hoge/Hoge2.txt
rIs the default variable
$_Option to replace and return as a scalar value. The feature is that the original character string replaced is not changed.
% tree . └── Hoge ├── Hoge1.txt ├── Hoge2.txt └── Hoge3.txt
% find `pwd` -name "*Hoge*" -print | perl -nle 'rename $_, s|Hoge|hoge|r' % find `pwd` -name "*Hoge*" -print | perl -nle 'rename $_, s|Hoge|hoge|r'
% tree . └── hoge ├── hoge1.txt ├── hoge2.txt └── hoge3.txt
I couldn't overwrite the old directory name in one go, so I ended up hitting the command twice. To be honest, it's annoying. If you have a smarter solution, please let me know: bow: