1

This question already has an answer here:

I have a line like this in my script:

rm "$TEMP_DIR/*.txt"

It fails with this output:

rm: cannot remove 'temp/*.txt': No such file or directory

I don't understand why doesn't that work. What am I doing wrong?

marked as duplicate by Jeff Schaller, Gilles bash Dec 10 '18 at 13:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Because you're using quotes in the command, rm thinks you want a filename with a literal * character, it's not expanding that as a wildcard. Try it without the quotes to match all files ending with .txt instead:

rm "$TEMP_DIR"/*.txt

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