Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I compare the current date/time to the modification date/time of a file?

0
Posted

How do I compare the current date/time to the modification date/time of a file?

0

Hi Bill, To get the modification date/time of a file, issue the command without the brackets <>: $ date -r To get the current date/time, issue the command: $ date To compare the two, save each in a variable, and then compare the values of the variables via picking off the delimited fields of the date/time. To save the current date/time in a variable, issue the command: $ date=`date` Then to display the value of the variable date, issue the command: $ echo “date = $date” To save the modification date/time of a file, issue the command: $ modtime=`date -r ` The to display the value of the variable modtime, issue the command: $ echo “modtime = $modtime” To compare the current/time vs modification time of the file, you will need to use one of awk, nawk or gawk – gawk or nawk would be a better choice than awk. Here is an example: Let’s say that the output of each command above echos the following values: modtime = Fri Apr 17 17:14:40 EDT 2009 and date = Wed Jun 3 16:13:1

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123