1

I have a file in a particular location. The file name is in format StaticData_Sets_yyyymmdd-hh:mm:ss.txt

This file is generated everyday with current date and timestamp.The string StaticData_Sets_ remains same for all files and only the date and time varies.

I just want to find the file with current day stamp(irrespective of time). And check the size of the file is 0 or not.

marked as duplicate by jimmij, don_crissti, jasonwryan, Ramesh, Braiam Nov 2 '14 at 23:38

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.

2

You can get the current date in that format with:

date +%Y%m%d

so the following command should find today's file and show its size:

ls -l StaticData_Sets_$(date +%Y%m%d)*.txt

or

find . -name "Static_Data_Sets_$(date +%Y%m%d)*.txt" -ls

You could sort the output using ls -lt and look at the topmost entry, which should be either today, or yesterday. In that case you would have to remember yourself what date it is.

  • Thanks. I just want to know what is wrong wit this command find . -name 'StaticData_Sets_$(date +"%Y%m%d")*'. When i try this it doenst work out. – Jaipreet Nov 2 '14 at 18:44
  • 1
    That just finds the file it doesn't show the size, for that you would need to add -ls at the end. If that is not it, what is not working out? – Anthon Nov 2 '14 at 18:47
  • Could you please help me perform the same task using find command. – Jaipreet Nov 2 '14 at 18:54
  • @Jaipreet I updated the answer – Anthon Nov 2 '14 at 18:58

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