Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried running

locate *.orig | xargs rm

but it said No such file or directory

I've seen ways to do it with find but locate returns the full path to the object so it should be possible

share|improve this question
up vote 12 down vote accepted

If filenames contain spaces you should use

locate -0 $something | xargs -0 rm


locate $something | while read f; do rm "$f"; done

Also, you should protect *.orig with quotes, to avoid the shell expansion, and pass it to locate untouched.

share|improve this answer
What do you mean by "shell expansion"? – soldier.moth Oct 22 '10 at 20:58
+1 for your second example. I always use | while read since my home directory is full of files with spaces. – sirlancelot Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern *.orig, the shell will expand the pattern to, say, file1.orig file2.orig ..., so that locate will not see the exact string *.orig as it should. – enzotib Oct 23 '10 at 5:39
@enzotib Great! Thank's – somethingSomething Feb 21 '15 at 20:51

It's xargs not xarg

share|improve this answer
That's what I meant was typing question from memory thank you though. – soldier.moth Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after | – maco Oct 22 '10 at 19:45

The command locate *.orig | xargs rm does work actually but what was happening was that locate was finding *.orig files in the trash can and rm spits out the error No such file or directory when trying to delete files in the trash can.

share|improve this answer
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question. – enzotib Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later. – soldier.moth Oct 23 '10 at 6:25

locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.

Just use

locate .orig

and if that gets you what you need

locate .orig | xargs rm

or, as enzotib mentioned

locate -0 .orig | xargs -0 rm

if you have Whitespace in the filenames.

share|improve this answer

A trick : Save all paths in tmp file . then , Loop on it:

locate .orig /tmp/tmp.txt
while read line
    rm "$pth" 
done < /tmp/tmp.txt

rm -rf /tmp/tmp.txt 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.