IBM AIX: core-shell: show date of modification of file

一个人想着一个人 提交于 2019-12-01 12:09:01

You can use istat:

$ istat  test.ksh
Inode 86741 on device 10/8 File
Protection: rw-r-----
Owner: 6361(user2) Group: 621(norgroup)
Link count: 1 Length 116 bytes
Last updated: Thu Jun 9 14:25:11 EDT 2011
Last modified: Thu Jun 9 14:25:11 EDT 2011
Last accessed: Fri Jan 20 16:08:46 EST 2012

See my blog - AIX version of stat command – Command to get File Timestamp

Does AIX have stat? Maybe you can do:

stat -c "%y  %n" *

You'd probably do best to install the relevant GNU packages. There isn't a simple alternative unless you like writing your own programs. The core AIX facilities do not make that sort of thing easy - unless you drop into Perl. (I'm pretty sure that Perl is installed and the code can be written so it will work even with the rather antiquated version of Perl you're likely to find on AIX.)

I use this Perl one-liner:

perl -e 'my ($sec, $min, $hour, $mday, $mon, $year) =localtime((stat(shift))[9]);printf("%04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec)' /etc/passwd

Or like this in bash:

    filetime=$(perl -e 'my ($sec, $min, $hour, $mday, $mon, $year) =localtime((stat(shift))[9]);printf("%04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec)' /etc/passwd)
echo $filetime

For your application you may want to remove the \n.

The advantage of this over the accepted answer is:

  1. This runs across more platforms,
  2. You are in control of the time format and can make it machine friendly.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!