File Info
Obtaining information about files in a script using the stat command, which is available independently of the bash shell.
Verbose File Info
Without any options, you get everything you could possibly want to know and then some:
$ stat index.html File: 'index.html' Size: 2417 Blocks: 24 IO Block: 4096 regular file Device: 18h/24d Inode: 9439118 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/jcdusse) Gid: ( 1000/jcdusse) Access: 2016-07-14 07:59:19.071077490 +0200 Modify: 2010-08-14 06:53:59.000000000 +0200 Change: 2012-09-23 11:39:20.509256034 +0200 Birth: -
To get the info in a form usable in scripts, specify the exact bit of info required using --format.
File Size
size=$(stat --format=%s $0) echo 'This script is '"${size}"' bytes'
File Permissions
$ stat --format='%A %a' . drwxr-xr-x 755
File Owner
$ stat --format=%U . jcdusse
File Type
$ stat --format=%F . Directory
Format
Handily, the --format (or if you must, -c) allows separators directly in the argument string:
$ stat --format=xx'%Ayy%a'zz . xxdrwxr-xr-xyy755zz
Path
Given a relative path, sometimes you need the absolute ("real") path:
$ realpath ~ /home/efudd