4

Say I have several files that are generated by a script and follow the pattern:

yyyymmdd_fileName.fileExtension

And yyyymmdd (i.e. 20170202) is a date, where year is 2017, month is February and day is the 2nd).

I know I can get the complete file name and extract the date part, but how do I make it a date element so I can compare with the current date provided by date?

2 Answers 2

3

Use -d arg of date.

man date

   -d, --date=STRING
          display time described by STRING, not 'now'
$ date -d 20170202
Thu Feb  2 00:00:00 CET 2017

To ease the comparsion, you can use the unixdate format

$ date -d 20170203 +%s
1486076400
1
  • -d is specific to GNU date; on BSD date it sets the kernel's value for daylight saving time.
    – John N
    Feb 2, 2017 at 10:28
0

Another option is to use touch. This should work on most systems, but you need to specify time as hhmm.ss. I normally use 1200.00.

touch -t 201702021200.00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .