-2

How can I print out the size of a file in Kbytes in my Bash script

jww
  • 97,681
  • 90
  • 411
  • 885
  • No ,,,,,,,,,,,, – Anas Abdallah Oct 29 '19 at 13:32
  • 1
    How doesn't it answer your question? – Benjamin W. Oct 29 '19 at 13:38
  • [How can I get the size of a file in a bash script?](https://unix.stackexchange.com/q/16640), [Show human readable file size in du](https://unix.stackexchange.com/q/81374), [How do I get the find command to print out the file size with the file name?](https://stackoverflow.com/q/64649/608639), [How to get total size of folders with find and du?](https://stackoverflow.com/q/9794791/608639), [How to list the size of each file and directory and sort by descending size in Bash?](https://stackoverflow.com/q/7463554/608639), etc. – jww Oct 29 '19 at 15:01

1 Answers1

2

The size of a file can be checked using the du command.

du -sh is used to display the size of a file in the easiest human readable way. If a file is 16K, it will show 16KB, if it is 16MB it will show 16MB.

Without the h flag, du by default shows you the disk space in KB as per the examples below:

du -sh /var/log/secure
13M     /var/log/secure
du -s /var/log/secure
13176   /var/log/secure

With that being said, the du command can be put into your bash script to return the size of the file in KB which is what you are trying to achieve.

jww
  • 97,681
  • 90
  • 411
  • 885