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

自作多情 提交于 2019-12-04 02:15:52

问题


I'd like to do something like this with bash (see time when file was last modified):

ls -lha
ls --full-time

but I must use core-shell on AIX. How can be so achieved?


回答1:


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




回答2:


Does AIX have stat? Maybe you can do:

stat -c "%y  %n" *



回答3:


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.)




回答4:


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.


来源:https://stackoverflow.com/questions/8940478/ibm-aix-core-shell-show-date-of-modification-of-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!