0

i have a problem with a wordpress website which are using external theme made by themefie.com , this website is restricted by google and some how google restricted my website too because i am using there theme .

I've searched for themefie.com inside my website public_html dir , and i've found a lot of files contain themefie.com , i believe i should remove this domain from my wordpress files so google will remove the restriction on my website .

but the problem is i have found over 500 file has themefie.com inside it , how i can use SSH root command to find and replace themefie.com with something else ?

Grep sample output :

zes":[]},"title_typography_font_weight":"400","_margin":{"unit":"px","top":"0","right":"0","bottom":"20","left":"0","isLinked":false},"text_align_mobile":"left"},"elements":[],"widgetType":"image-box"},{"id":"72847bd","elType":"widget","settings":{"image":{"url":"https:\/\/themefie.com\/wp\/foodka\/wp-content\/uploads\/2021\/08\/envelope.png","id":452,"alt":"","source":"library"},"title_text":"[email protected]","description_text":"","position":"left","image_space":{"unit":"px","size":10,"sizes":[]},"image_size":{"unit":"%","size":5,"sizes":[]},"content_v
<guid isPermaLink="false">https://themefie.com/wp/foodka/?p=495</guid>
2
  • You are parsing JSON and XML files. Can you say something about the structure of these files and what you want to change in them so that we can show how to do that using the correct tools? Example: "I want to change themefie.com to something else in any url key in the JSON file and in any guid node in the XML file".
    – Kusalananda
    Commented Oct 17, 2023 at 7:38
  • @Kusalananda it not only json files , this word themefie.com is inside html/php/sql/json etc . when i use grep "themefie.com" its showing a lot kind of files has this work , i want to remove this word or replace it with anything else no matter the file extenstion
    – Kodr.F
    Commented Oct 17, 2023 at 7:46

1 Answer 1

3

You asked for a command to remove all occurrences of a string in multiple files, so here it is:

find /home/xxx/public_html -type f -exec sed -i 's/themefie\.com//g' {} \;

If you want to replace this string with something else:

find /home/xxx/public_html -type f -exec sed -i 's/themefie\.com/SOMETHING_ELSE/g' {} \;

You can back up the files like this (will add .bak extension to all modified files):

find /home/xxx/public_html -type f -exec sed -i.bak 's/themefie\.com/SOMETHING_ELSE/g' {} \;

However, this is a very brutal method, and you will very probably break many things issuing this command.

If you can change your theme for something else, then you should probably go this way.

Whatever happens, don't forget to back up your data before running any of these commands.

As suggested by @Stephen Kitt in the comments, you can use find in a different way, which is more optimized while processing multiple files using sed. Quote from the find man page:

-exec command ;
              Execute command; true if 0 status is returned.  All following arguments to find are taken to be arguments to the command until an argument
              consisting of `;' is encountered.  The string `{}' is replaced by the current file name being processed everywhere it occurs in the  argu‐
              ments  to the command, not just in arguments where it is alone, as in some versions of find.  Both of these constructions might need to be
              escaped (with a `\') or quoted to protect them from expansion by the shell.  See the EXAMPLES section for examples of the use of the -exec
              option.   The specified command is run once for each matched file.  The command is executed in the starting directory.  There are unavoid‐
              able security problems surrounding use of the -exec action; you should use the -execdir option instead.

-exec command {} +
              This variant of the -exec action runs the specified command on the selected files, but the command line is built  by  appending  each  se‐
              lected  file name at the end; the total number of invocations of the command will be much less than the number of matched files.  The com‐
              mand line is built in much the same way that xargs builds its command lines.  Only one instance of `{}' is allowed within the command, and
              it  must appear at the end, immediately before the `+'; it needs to be escaped (with a `\') or quoted to protect it from interpretation by
              the shell.  The command is executed in the starting directory.  If any invocation with the `+' form returns a non-zero value as exit  sta‐
              tus,  then  find returns a non-zero exit status.  If find encounters an error, this can sometimes cause an immediate exit, so some pending
              commands may not be run at all.  For this reason -exec my-command ... {} + -quit may not result in my-command actually  being  run.   This
              variant of -exec always returns true.

So this will give you:

find /home/xxx/public_html -type f -exec sed -i 's/themefie\.com/SOMETHING_ELSE/g' {} \+
7
  • where i can specify the directory ? for example the website is inside /home/xxx/public_html i want to find and replace only in this dir
    – Kodr.F
    Commented Oct 17, 2023 at 8:18
  • I edited my answer. I first wrote it using the ., which means it will run in the current directory (where you're when you launch the command). I hope it’s clearer this way.
    – ramius
    Commented Oct 17, 2023 at 8:20
  • great , thank u . i will try it and let u know the result
    – Kodr.F
    Commented Oct 17, 2023 at 8:25
  • Okay, but you've been warned, there is a huge risk of breaking something :)
    – ramius
    Commented Oct 17, 2023 at 8:27
  • 2
    You can use + instead of \; to process multiple files per sed invocation. Commented Oct 17, 2023 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .