How to get last month files. Ex : 1st Jan i have to get Dec 31 days files and on Feb 1st i have to get Jan 31 days files and on Mar 1st i have to get Feb 28 days files. Below are the example files with date and timestamp.
aaa.txt.timestamp
aaa.txt.timestamp
aaa.txt.timestamp
Please let me know how can i achieve this in a command and redirect all the files to one file.
Thanks.
The simplest, accurate way is to use the modify time stamp and the 'find' comand. Some versions of 'find' allow direct references ( -newerXY datetime1 \! -newerXY datetime2, others need marker files ( -newer file1 \! -newer file2 ) that you can make with 'touch'. The logic should be >= MM/01/YYYY 00:00:00 but < MM+1/01/YYYY 00:00:00. Obviously, it needs to be at least the next month to get a complete list.
Later GNU date commands can help you generate the date strings, or you may need to write a little year-month date arithmetic in shell $(( ... )), i.e., 201501 - 1 = 201500, needs correction from 2015 to 2014 and 00 to 12.
Working off the first second of the month frees you from month length and leap year issues.
There is a little booble when DST time shifts in and out, as the month will be a hour short or long. You might want to export a $TZ that does not do DST (GMT?), so you do not have some files never or twice.
Generally, it's doable, but not "in a command", though (imho). Your timestamps are not meaningful, at all, because there are tons of different timestamps. Please update your post with representative timestamps. Ideally, they are in YYYYMMDD format. Do you have a bash and GNU cal on your system?
What have you tried so far?
The 2 above posts give you the idea... The command there are no for such task and the script you will have to write if you have not found one in the numerous fora here, we are here do help you with the writing, not to do the job for you
I don't think s/he wants last year's december files, but just last month's files even if run in January. Try - should GNU date be available on your system -
ls aaa.txt.$(date -d-$(( $(date +%d) ))days +%Y%m)??