0

I need to delete thousands of files that have similar names but different endings. They were created by malware that attacked a client's shared hosting and infected multiple wordpress sites. I'm using SSH in place of the cPanel file manager because it won't let me delete that many files at once.

The files are all named work.php.xxxx The x's represent numbers between 0 - 9999 i.e "work.php.2048" They are all in one folder.

Is there an SSH command that would allow me to delete them and only them in mass?

This is different from the suggested duplicate because the files all have unique endings after the .php extension, the suggested solution to that problem would not work for me.

Giacomo1968
  • 58,727

1 Answers1

0

I recommend doing this in two steps to make sure you get the results you want. First, move files to an empty folder.

user@linux:/.../somefolder#                 cd [TargetFolder]
user@linux:/.../TargetFolder#               mkdir DeleteFolder
user@linux:/.../TargetFolder#               find ./ -regex './work.php.[0-9][0-9][0-9][0-9]' -exec mv {} DeleteFolder/ \;
user@linux:/.../TargetFolder/DeleteFolder#  cd DeleteFolder
user@linux:/.../TargetFolder/DeleteFolder#  ls -l *

if your DeleteFolder contains only the files you want to delete, do the following:

user@linux:/.../TargetFolder/DeleteFolder#  rm work.php.[0-9][0-9][0-9][0-9]

You can obviously use rm work.php.[0-9][0-9][0-9][0-9] within the target folder if you want to do it in one step. I am personally quite cautious when using rm - hence then two-step method.

Brian
  • 1,085