1

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: http://www.commandlinefu.com/commands/view/6234/use-a-variable-in-a-find-command.-useful-in-scripting.

Without luck..

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

Thanks a lot!

3
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.

| improve this answer | |
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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