Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

linux - I want to delete all index.php file only if the code inside contain specific expres

I want to delete all index.php files, in all directories and sub-directories file that had this specific expression on it's code

if ( !class_exists( 'WPPluginsOptions' ) )

can we do this in ssh using Linux command or whatever

question from:https://stackoverflow.com/questions/65838188/i-want-to-delete-all-index-php-file-only-if-the-code-inside-contain-specific-exp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Find all files named index.php using the linux find command.
  2. Search in the files for the string if ( !class_exists( 'WPPluginsOptions' ) ) using the linux grep command with the -l flag. (Only output files that match what you are looking for )
  3. Use the linux xargs command to send the list of files from the grep command to the linux rm command.

All together.

find -L /var/www -iname "index.php" -exec egrep -l 'if ( !class_exists( '"'"'WPPluginsOptions'"'"' ) )' {} + | xargs rm -f

Be careful with this command because it doesn't ask you before deleting files. You should test it in a safe place before running it in production.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...