Find and replace for WordPress with SSH
For experienced users, it can be more efficient to use SSH when managing WordPress, and performing tasks such as a find and replace in the database.
- Connect to your hosting account with SSH.
- Export your WordPress database.
Open the dump file with the vim text editor with the following command:
vim filename.sql
Update the command with the following information:
- filename.sql is the name of the dump file you just created when you exported the WordPress database
Note: If your current working directory is different than your working directory at the time the dump file was created, then you will need to include the path to the file in the command. For example:
vim /home/user/public_html/filename.sql- Enter command mode by typing the colon (:) character.
- Once in command mode, execute a find and replace with the following command:
%s/OldDomain/NewDomain/g
Update the command with the following information:
- OldDomain is your old domain or data
- NewDomain if your new domain or data
- Press Enter to run the command, which will execute a find and replace of the old domain/data with the new domain/data.
- Press Esc to exit the insert/append mode.
- Type the following command to enter command mode, save the file and exit
:wq
- Import your updated database using SSH.
Related steps
- If you're using this process to change your domain name, then you may also need to update the domain on your hosting account.
More info
- If you are unfamiliar with using SSH, you may wish to try using a Search & Replace plugin or text editor.
- If you need any assistance with a find and replace, our WordPress Premium Support team can do that for you.