【Perl】Solarisでstatしたかった、ので。
ざっくり、シェルスクリプトとPerlで実装。
色々参考にしつつ。一部変なコメントが入っていますがそれはそれで。[stat.sh]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
Usage(){ | |
cat << __EOT__ >&2 | |
ファイルのステータスを確認します。 | |
Usage:`basename $0` ファイル名 | |
【使用例】 | |
$ `basename $0` file.txt | |
__EOT__ | |
} | |
# 引数エラーチェック | |
if [ "$1" = "--help" -o "$1" = "" ] ; then | |
Usage | |
exit 1 | |
fi | |
# 入力ファイルチェック | |
file=$1 | |
if [ ! -r "${file}" ] ; then | |
echo "'"${file}"'" が存在しないか、読み込めません >&2 | |
exit 9 | |
fi | |
# -------------------------------------------------- | |
perl -e ' | |
use Fcntl ":mode"; | |
@stats=stat($ARGV[0]); | |
map{ | |
print $_ . "\n"; | |
} ( | |
" File: " . $ARGV[0], | |
" Size: " . @stats[7], | |
"BlockSize: " . @stats[11], | |
" Blocks: " . @stats[12], | |
# " Type : " . @stats[6], # 理解できたら対応するかも? | |
# " Device : " . @stats[0], # 理解できたら対応するかも? | |
# " Inode: " . @stats[1], # Deviceが見えなければきっと無意味 | |
" Links: " . @stats[3], | |
sprintf(" Access: %03o", S_IMODE(@stats[2])), | |
" Uid: " . getpwuid(@stats[4]) . " (" . @stats[4] . ")", | |
" Gid: " . getgrgid(@stats[5]) . " (" . @stats[5] . ")", | |
" Access: " . localtime(@stats[8]), | |
" Modify: " . localtime(@stats[9]), | |
" Change: " . localtime(@stats[10]) | |
); | |
' "${file}" |