Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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

1 Answer 1

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

 
discard

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.