1

My original working directory hierarchy:

$ find
.
./usr1
./usr1/.vimrc
./usr2
./usr2/.vimrc

I want to add one line -- "set number" -- to all .vimrc files. So I ran this command:

find -name ".vimrc" -exec echo "set number" >> {} \;

But, all .vimrc files stay the same, and there is a new-created {} file in my working directory:

$ find
.
./usr1
./usr1/.vimrc
./{}
./usr2
./usr2/.vimrc

What is wrong? How can I do that correctly?

1

If you want to redirect output of command with -exec, It is better to execute shell command ; Try the following syntax in your case:

find -name ".vimrc" -exec sh -c 'echo "set number" >> {}' \;

This will work as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.