bash IBM AIX:core-shell:显示文件修改日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8940478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:22:26  来源:igfitidea点击:

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

bashaix

提问by Xorty

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

我想用 bash 做这样的事情(查看上次修改文件的时间):

ls -lha
ls --full-time

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

但我必须在 AIX 上使用 core-shell。怎么可以这样实现?

回答by Jason Liang

You can use istat:

您可以使用 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

看我的博客——AIX版的stat命令——获取文件时间戳的命令

回答by glenn Hymanman

Does AIX have stat? Maybe you can do:

AIX 有stat吗?也许你可以这样做:

stat -c "%y  %n" *

回答by Jonathan Leffler

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

您可能最好安装相关的 GNU 软件包。除非您喜欢编写自己的程序,否则没有简单的替代方案。核心 AIX 工具不会使这种事情变得容易——除非您使用 Perl。(我很确定 Perl 已安装并且可以编写代码,因此即使使用您可能在 AIX 上找到的相当过时的 Perl 版本,它也能正常工作。)

回答by Michael Potter

I use this Perl one-liner:

我使用这个 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:

或者像这样在 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.

对于您的应用程序,您可能希望删除 \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.
  1. 这在更多平台上运行,
  2. 您可以控制时间格式并使其易于机器使用。