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.

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!

share|improve this question
add comment

1 Answer 1

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
add comment

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.