Search code examples
bashshellunixunix-timestamp

How to subtract today's date with a file's modification date in unix?


For example: echo $(date) - $(date -r sample.txt)

Output: 90 days(for example)


Solution

  • Use %s seconds since 1970-01-01 00:00:00 UTC as in

    echo $(expr $(date +%s) - $(date -r sample.txt +%s)) #!/bin/sh
    echo $(($(date +%s) - $(date -r sample.txt +%s))) #/bin/bash