I want to get the number of days since file last modified date to today's date.
I use this $ ls -l uname.txt | awk '{print $6 , "", $7}'
but it gives me the last modified date. I want to know the number of days from a last modified date to today's date.
Any way to do this?
Instead of using ls
, you can use date -r
to tell you the modification date of the file. In addition to that, date
's %s
specifier, which formats the date in seconds since the epoch, is useful for calculations. Combining the two easily results in the desired number of days:
mod=$(date -r uname.txt +%s)
now=$(date +%s)
days=$(expr \( $now - $mod \) / 86400)
echo $days
Try creating a script:
#!/bin/bash
ftime=`stat -c %Y uname.txt`
ctime=`date +%s`
diff=$(( (ctime - ftime) / 86400 ))
echo $diff
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With