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

I'm trying to create a simple script that deletes files based on the ending of thier names and the date.

I can't figure out how to do this.

This is how I do it:

DA='date +%d'
find /var/www/data/files/ -name "*#$DA*"

I want to find all files that ends on this pattern.. So today it would be #06

I also tried

find . -iname \*${MYVAR}\* -print

As suggested here:

Without luck..

So can anyone help me use the find command searching for a var?

Thanks a lot!

share|improve this question
up vote 3 down vote accepted
find . -iname "*$(date +%d)*" -print

This should do the trick. With $() You can get the output of a command as an argument to another command.

share|improve this answer
Thanks a lot, that worked great! – Bolli Nov 6 '12 at 13:07
Similarly, you could do it with DA=$(date +%d), but unless you want it for something else, there's no real point in putting it in a variable first. – Gordon Davisson Nov 6 '12 at 16:20

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.