Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

The expected behaviour was to delete all .jpgs, but it deleted all files in the directory.

How can the command be changed to find and delete all xyz files?

share|improve this question
Remember that special symbols are processed by shell, not programs. * is replaced with file names before find or rm gets started. – gronostaj Dec 1 '13 at 13:16
Within find, the character that means "the name of the file just found" is {}. So if you want to delete all jpg files, you could say: find . -type f -name '*.jpg' -exec rm {} \; This deletes all files one by one, as soon as they are found. This is a waste (better do them all in one go), but illustrates that there a symbol which substitutes for the name of the file just found. – MariusMatutiae Dec 1 '13 at 15:12
up vote 5 down vote accepted

You executed rm * result1.jpg result2.jpg result3.jpg ..., not rm result1.jpg result2.jpg result3.jpg ..., thereby deleting everything matching * through shell expansion.

But you don't even need xargs for this simple task.

Run find ... -type f -print first, in case you're not confident about your expression. Make sure you like the results.

Then, run find ... -type f -delete.

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.