How to use find command to delete files matching a pattern?

I generally find that using the -exec option for find to be easier and less confusing. Try this:

find . -name vmware-*.log -exec rm -i {} \;

Everything after -exec is taken to be a command to run for each result, up to the ;, which is escaped here so that it will be passed to find. The {} is replaced with the filename that find would normally print.

Once you've verified it does what you want, you can remove the -i.


If you have GNU find you can use the -delete option:

find . -name "vmware-*.log" -delete

To use xargs and avoid the problem with spaces in filenames:

find . -name vmware-*.log -print0 | xargs -0 rm

However, your log files shouldn't have spaces in their names. Word processing documents and MP3 files are likely to have them, but you should be able to control the names of your log files.