Thursday, March 7, 2019

how to get symbolic link file size in linux ?

The name of the symbolic link remains fixed, but the file it is linked to is constantly changed by another application . The Motion application ensures that the symbolic link points to the correct file.

symbolic links: Refer to a symbolic path indicating the abstract location of another file

Using stat command will get  symbolic file size.

stat - display file or file system status

Syntax :

stat -Lc %s  < symbolic>


-L, --dereference
                             follow links
-c  --format=FORMAT
                              use the specified FORMAT instead of the default; output a newline after            each use of FORMAT

%s     total size, in bytes

                ls -lrt script*

 -rw-rw-r-- 1 ram ram 29366 Mar  6 01:37 script.txt
lrwxrwxrwx 1 ram ram    10 Mar 7 14:34 script -> script.txt

stat -Lc %s script

Example2: using du command

du -b $(readlink -f script)

29366 /home/ram/script.txt

No comments:

Post a Comment