Background
I am new to linux/unix (I'm on a mac. Don't know which I am using), but someone made a lot of folders and files under the wrong name, and I need to go in and replace everything with the correct name. E.g. she named it apple instead of orange.
What I need to do
I navigated to the directory of interest, and within that directory, I need to:
Replace the word apple with orange in the name of any subfolder or file or directory
Replace the word apple with orange within any files (both text and non-text)
What I have tried
I tried this command:
grep -lr "apple" . | xargs sed -i "s/apple/orange/g"
and that didn't work at all
I also tried :
find ./ -exec sed -i 's/apple/orange/g' {} \;
This replaced a lot of the instances, but not all. And it does not replace the word within file/folder/directory names
Please help!
find
to get all files withapple
in the name, then for each of those files, usemv
to rename the file changingapple
toorange
.