Reputation: 272382
Suppose I want to go through each file (recursively too), and replace everything with:
{{ MEDIA_URL }}
with:
{% media_url %}/
What command can I run in Linux to replace the former with the latter, in all my files, recursively?
Upvotes: 1
Views: 194
Reputation: 586
As much as possible, I use xargs instead of -exec. With a -exec, you'll have one process launched for each file while with xargs you will have only one process. You must use the sed option -s for that. This command is faster when you have several files:
find ./ -type f | xargs sed -s -i 's/{{ MEDIA_URL }}/{% media_url %}\//g'
Upvotes: 3
Reputation: 53516
How about a sed solution...
find ./ -type f -exec sed -i 's/{{ MEDIA_URL }}/{% media_url %}\//g' {} \;
Updated: added /g as per a commenter suggested
Updated: somehow unicode chars got copied in there
Upvotes: 6