bash stat - ghdrako/doc_snipets GitHub Wiki

filename=first.txt
filesize=$(stat --format=%s "$filename")
size=$(stat -c%s "$FOLDERNAME")
stat -c "%a %U %G %n" /etc/nsswitch.conf
644 root root /etc/nsswitch.conf

To dereference (follow) the symlink and display information about the file to which the symlink points, use the -L, (--dereference) option:

  • %N quoted file name with dereference if symbolic link
get_symlink_target(){
    local symlink_path=$1
    local target=$(stat -c %N "$symlink_path" | awk -F' -> ' '{print $2}')
    echo "$target"
}