Determining age of a file in shell script

后端 未结 6 1097
暖寄归人
暖寄归人 2021-01-04 18:28

G\'day,

I need to see if a specific file is more than 58 minutes old from a sh shell script. I\'m talking straight vanilla Solaris shell with some POSIX extensions i

6条回答
  •  攒了一身酷
    2021-01-04 18:35

    You can use ls and awk to get what you need as well. Awk has a c-ish printf that will allow you to format the columns any way you want.

    I tested this in bash on linux and ksh on solaris.

    Fiddle with options to get the best values for your application. Especially "--full-time" in bash and "-E" in ksh.

    bash

    ls -l foo | awk '{printf "%3s %1s\n", $6, $7}'

    2011-04-19 11:37

    ls --full-time foo | awk '{printf "%3s %1s\n", $6, $7}'

    2011-04-19 11:37:51.211982332

    ksh

    ls -l bar | awk '{printf "%3s %1s %s\n", $6, $7, $8}'

    May 3 11:19

    ls -E bar | awk '{printf "%3s %1s %s\n", $6, $7, $8}'

    2011-05-03 11:19:23.723044000 -0400

提交回复
热议问题