Shell – How to find a file with a name which depends on the current date (and a random component)

datefindshell

I have to check a particular path every day and find the file with a name of the form:

StaticData_Sets_yyyymmdd-232550.txt

The date in the name after the string StaticData_Sets_ is updated every day depending on the system date. The number after the date is random.

How can I find the file for the current date in Unix?

Best Answer

Use command date to generate current day with proper output format, and append that string to file name in the following fashion:

filename=StaticData_Sets_$(date +"%Y%m%d")
find . -name "$filename*.txt"
Related Question