There are various ways and command tricks to find out file size under UNIX / Linux shell.
stat command example
You can display file or file system status with GNU/stat command. The -c option can be used to get specific information about file such as size in bytes:$ stat -c %s fw8ben.pdf Sample output:
74777Refer to your local stat command man page for exact syntax, for example, FreeBSD stat works as follows:
$ stat -s file.txtls command example
Use ls command as follows to get human readable format:$ ls -lah fw8ben.pdf | awk '{ print $5}'Sample output:
74KYou can store output to a variable:
$ s=$(ls -lah idg.fw8ben.pdf | awk '{ print $5}')
$ echo $sOR
$ s=$( stat -c %s fw8ben.pdf)
$ echo $s
No comments:
Post a Comment