bash stat - ghdrako/doc_snipets GitHub Wiki
- https://man7.org/linux/man-pages/man1/stat.1.html stat takes a lot of format switches, which restrict its output to exactly the information you are looking for.
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"
}