I have a list of about 200 image file names. On the web server there are multiple instances of files with these file names within a subfolder structure within one directory.
Is there a command I can run to find all instances of these file names and delete them?
example of file names
- image-488363450-1.jpg
- somename-186758341-1.jpg
- randomname-588968004-1.jpg
- blabla124405236-1-1.jpg
- someimage_MEDIUM.jpg
2
Answers
(this is actually from here)
Assuming that the file “badFiles” file holds a list of filenames that you would like to delete, and “myDirs” holds a list of subdirectories in which they could be, the following should work:
If the list of directories includes all subdirectories from your current working directory, then the following should work without creating the myDirs file:
To call this over SSH, you can put the contents of the below script into a file (in this example, I will use the location ${HOME}/bin/killImages.sh):
Edit ~/bin/killImages.sh, and use the contents below. Once complete, write and save.
Then make your script executable:
Then on your local system, execute:
If you need to manually upload the list of bad files first, you would simply scp this into place before kicking off the script:
Hope this helps.