How can I delete a specific file from a set of results using the find command in Linux?
Posted
by
PeanutsMonkey
on Super User
See other posts from Super User
or by PeanutsMonkey
Published on 2012-09-22T08:11:14Z
Indexed on
2012/09/22
9:40 UTC
Read the original article
Hit count: 278
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 {} after
rm`? e.g.
find . -maxdepth 1 -iname \*.doc\* -exec rm {Dummydata.docx} Sample.doc
Is there a better way of doing it?
© Super User or respective owner