I’m trying to purge all thumbnails created by WordPress because of a CMS switchover that I’m planning.
find -name *-*x*.* | xargs rm -f
But I dont know bash or regex well enough to figure out how to add a bit more specifity such as only the following will be removed
All generated files have the syntax of
<img-name>-<width:integer>x<height:integer>.<file-ext> syntax
You didn’t quote or escape all your wildcards, so the shell will try to expand them before
find
executes.Quoting it should work
Remove the
echo
when you’re satisfied it works. You could also check that two of the fields are numbers by switching to-regex
, but not sure if you need/want that here.regex soultion
Note: I’m assuming
img-name
andfile-ext
can only contain lettersYou can try this:
If you have spaces in the path:
Example:
The below GNU
find
command will remove all the files which contain this<img-name>-<width:integer>x<height:integer>.<file-ext> syntax
string. And also i assumed that the corresponding files has.
in their file-names.Explanation:
.
Directory in which find operation is going to takeplace.(.
represnts your current directory)-name "*.*"
File must have dot in their file-names.-type f
Only files.-exec grep -l '<img-name>-<width:integer>x<height:integer>.<file-ext> syntax' {}
print the file names which contain the above mentioned pattern.xargs rm -f
For each founded files, the filename was fed into xargs and it got removed.