Sam's Tech Blog

'You can check out any time you like, But you can never leave!'

2019-08-21

Replace strings

How to: Replace strings from command line

Replace strings

Here are some of my favorites:

cd /etc/php/

find . -type f | xargs sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/g'
find . -type f | xargs sed -i 's/post_max_size = 8M/post_max_size = 100M/g'

/etc/init.d/php* restart
/etc/init.d/apache2 restart

In vi use : and then give the command below replace rsync -a with rsync -a --delete (this also works with slash /)

%s@rsync -a@rsync -a --delete@g

You can use sed in command line or bash scripts to do the same by giving a command like this...

sed -i 's#'"StringOLD"'#'"StringNEW"'#g' /var/www/site.id/pagekit/pagekit.db

When replacing strings inside liteSQL file the OLD string and the NEW string must have exactly the same number of characters.