162

When I revert in Mercurial, it leaves several .orig files. I would like to be able to run a command to remove all of them.

I have found some sources that say to run:

rm **/*.orig

But that gives me the message:

rm: cannot remove `**/*.orig': No such file or directory

I have also tried these commands:

rm -rv *.orig
rm -R *\.orig
Zanna
  • 72,312
JD Isaacks
  • 5,497

4 Answers4

287

Use the find command (with care!)

find . -name '*.orig' #-delete

I've commented out the delete command but once you're happy with what it's matching, just remove the # from the line and it should delete all those files.

Oli
  • 299,380
29

"find" has some very advanced techniques to search through all or current directories and rm files.

find ./ -name ".orig" -exec rm -rf {} \;
user2038042
  • 391
  • 3
  • 4
14

I have removed all files that starts with .nfs000000000 like this

rm .nfs000000000*
8

The below is what I would normally do

find ./ -name "*.orig" | xargs rm -r

It's a good idea to check what files you'll be deleting first by checking the xargs. The below will print out the files you've found.

find ./ -name "*.orig" | xargs

If you notice a file that's been found that you don't want to delete either tweak your initial find or add a grep -v step, which will omit a match, ie

find ./ -name "*.orig" | grep -v "somefiletokeep.orig" | xargs rm -r