I changed project name and now I have many files an directories with old name. How to replace these names with find?
find . -name "*old_name*" -exec ???
This find
should work for you:
find . -name "old_name" -execdir mv "{}" new_name +
This will find files with the name old_name
from the current dir in all sub directories and rename them to new_name
.
Below is what I have used in the past. The biggest gotcha is the RHEL rename (c) vs Debian rename (perl) - They take different options. The example below uses RHEL c based rename command. Remove the '-type f' to also rename the directories.
find . -type f -name "*old_name*" -print0 | xargs -0 -I {} /usr/bin/rename "old_name" "new_name" {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With