ls 出力を変更せずに AIX でファイル所有者を取得するにはどうすればよいでしょうか?

ls 出力を変更せずに AIX でファイル所有者を取得するにはどうすればよいでしょうか?

どうすれば確実にAIX でファイルの所有者を取得しますか? 信頼できるとは、 の出力を解析することではありませんls。Linux では、 を実行するだけですstat --printf=%U fooが、私は AIX 6.1 および 7.1 で作業しています。 を実行できることはわかっていますが、 AIX にはオプションistatがないため、出力をおよびを使用して変更する必要があり、望ましくありません。言い換えると、AIX のコア ユーティリティのみを使用して Linux をエミュレートするにはどうすればよいでしょうか?--printfistatgrepawkstat --printf=%U foo

答え1

これは、AIX で stat(1) のようなユーティリティを取得するために、しばらく前に作成したスクリプトです。 %U を追加しました。--printf とは少し動作が異なる -c オプションを使用する方が便利だとわかりました。コメント ブロックとして、Perl の stat 配列の便利なローカル コピーが含まれています。

#!/usr/bin/env perl -w
# emulate GNU coreutils stat command in a limited way
# -- only implemented a subset of the stat() options

use strict;
use Getopt::Std;
our $opt_c;

getopts('c:') or die "Usage: $0 [ -c (%n %i %u %g %s %U %X %Y %Z) ] file ...";
# default format is empty (not useful, but avoids 'undef' errors later)
$opt_c |= '';

for (@ARGV) {
  my @s = stat;
  next unless @s; # silently fail on to the next file
  my $p = $opt_c; # make a copy of the format string to mangle for each file

  # mangle and print
  $p =~ s/%n/$_/g;
  $p =~ s/%i/$s[1]/g;
  $p =~ s/%u/$s[4]/g;
  $p =~ s/%g/$s[5]/g;
  $p =~ s/%s/$s[7]/g;
  $p =~ s/%U/getpwuid($s[4])/eg;
  $p =~ s/%X/$s[8]/g;
  $p =~ s/%Y/$s[9]/g;
  $p =~ s/%Z/$s[10]/g;
  print "$p\n";

  #                 0 dev      device number of filesystem
  #                 1 ino      inode number
  #                 2 mode     file mode  (type and permissions)
  #                 3 nlink    number of (hard) links to the file
  #                 4 uid      numeric user ID of file's owner
  #                 5 gid      numeric group ID of file's owner
  #                 6 rdev     the device identifier (special files only)
  #                 7 size     total size of file, in bytes
  #                 8 atime    last access time in seconds since the epoch
  #                 9 mtime    last modify time in seconds since the epoch
  #                10 ctime    inode change time in seconds since the epoch (*)
  #                11 blksize  preferred block size for file system I/O
  #                12 blocks   actual number of blocks allocated

}

関連情報