Basis of ls, stat permits field seletion
stat [option] file...
Reference: File System attributes
|
> stat -f /bin File: "/bin" ID: 0 Namelen: 255 Type: ext2/ext3 Block size: 4096 Fundamental block size: 4096 Blocks: Total: 2510895 Free: 1663998 Available: 1534394 Inodes: Total: 2592691 Free: 2543983 > stat /bin File: `/bin' Size: 4096 Blocks: 16 IO Block: 4096 directory Device: 802h/2050d Inode: 16433473 Links: 2 Access: (0755/drwxr-xr-x) Uid:(0/root) Gid:(0/root) Access: 2009-02-08 12:53:27.000000000 -0500 Modify: 2009-01-09 05:46:10.000000000 -0500 Change: 2009-01-09 05:46:10.000000000 -0500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo " yy access modification change I am $0" export ccyymmdd=`date +"%Y-%m-%d"` export ccyy=`date +"%Y-"` /usr/bin/stat -c"%n %x %y %z" $* |sed "s/ /\\t/; s/$ccyymmdd/__-__-__/g; s/200/0/g; s/00000000 -0.00//g;"|column -t
stat [-FLnq] [-f format
| -l | -r | -s | -x]
[-t timefmt] [fileList …]
readlink [-n] [symbolicLink …]
Displays the target of a symbolic link. If file is not a symbolic exits with an error code of 1.
-l | |||||||||||||||||||||||||||||||||||||
%n newline , %t tab, %% percent,
%@ current file number in fileList
%formattingCharacters fieldSpecifier
% and the fieldSpecifier are required. formattingCharacters
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
234881033 176990 -rw-r--r-- 1 dgerman dgerman 0 7326645 "Mar 15 01:13:24 2008" "Jun 26 14:32:26 2007" "Jun 27 19:18:55 2007" "Jun 26 14:32:26 2007" 4096 14312 0 0aks.gz
| fieldSpecifier | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
p | ||||||||||||||||||||||||||||||||||||||||||||||||
Most formattingCharacters default to U
p (permissions) defaults to Octal
a, m, and c default to D and
Y, T, and N (symbolicTarget, fileType and Name), default to S.
Exit 0 on success, and >0 if an error occurs.
EXAMPLES
Given a symbolic link foo that points from /tmp/foo to /
> stat -F /tmp/foo
lrwxrwxrwx 1 user grp 1 Apr 24 16:37:28 2002 /tmp/foo@ -> /
> stat -LF /tmp/foo
drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
To initialize shell variables, use -s :
> csh > sh
% eval set `stat -s .cshrc` $ eval $(stat -s .profile)
% echo $st_size $st_mtimespec $ echo $st_size $st_mtimespec
1148 1015432481 1148 1015432481
to get a list of the kind of files including files pointed to if the file is a symbolic link:
$ stat -f "%N: %HT%SY" /tmp/*
/tmp/bar: Symbolic Link -> /tmp/foo
/tmp/output25568: Regular File
/tmp/blah: Directory
/tmp/foo: Symbolic Link -> /
to get a list of the devices, types and the major and minor device numbers, stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
[...]
Name: /dev/wt8
Type: Block Device
Major: 3
Minor: 8
Name: /dev/zero
Type: Character Device
Major: 2
Minor: 12
Display the permissions set on a file separately:
> stat -f "%Sp -> owner=%SHp group=%SMp other=%SLp" .
drwxr-xr-x -> owner=rwx group=r-x other=r-x
To determine the files that have been modified most recently, use:
> stat -f "%m%t%Sm %N" /tmp/* | sort -n |cut -f2- (cut discards first field, the modify time in decimal )
Apr 25 11:47:00 2002 /tmp/blah
Apr 25 10:36:34 2002 /tmp/bar
Apr 24 16:47:35 2002 /tmp/foo
Read, write or execute permissions of fileList are not required,
If no fileList is given, information is show for STDIN.
useful :
38294852 58542596 crw--w---- 1 dgerman tty 268435456 0
"Apr 19 20:53:01 2008" "Apr 19 20:53:01 2008" "Apr 19 20:53:01 2008" "Apr 19 20:53:01 2008" 131072 0 0 (stdin)
export ccyymmdd=`date +"%x"`
export yymmdd=`echo $ccyymmdd|sed "s/\/20/\//"`
/usr/bin/stat -t "%x %X " -f"%N %Sa %Sm %Sc" $* | sed "s'$yymmdd'__/__/__'g; s/\"//g" | column -t
traceroute __/__/__ 19:39:44 06/05/05 20:59:00 03/19/09 19:49:09
| FSF linux version | darwin |
-L |