How can I delete a specific file from a set of results using the find command in Linux?
- by PeanutsMonkey
I have the following command that lists all files with the extension doc, docx, etc.
find . -maxdepth 1 -iname \*.doc\*
The command returns numerous files some of which I would like to delete. So for example the results returned are
Example.docx
Dummydata.doc
Sample.doc
I would like to delete Sample.doc and Dummydata.docx. How do I delete the files using the -exec option. Am I able to pass in the names of the files e.g. rm Dummydata.docx Sample.doc hence the command would look as follows
find . -maxdepth 1 -iname \*.doc\* -exec rm Dummydata.docx Sample.doc
Can I pass the names of the files within {} afterrm`? e.g.
find . -maxdepth 1 -iname \*.doc\* -exec rm {Dummydata.docx} Sample.doc
Is there a better way of doing it?