Linux Commands Series 8 : Directories and Files 5 Compute the size of files 1
05/08/2020
One important thing to do when working with files and directories is to be able to compute the size of them, especially in human readable format (in KB, MB,GB..). We already saw a command which is able to do this, which is ls command. ls has two handy option which are -h and -si.
-h is used to display the sizes of files or directories in human readable format, the sizes are powers of 1024
--si is used to display the sizes in human readable format, but the sizes this times are powers of 1000, not 1204
h displays the sizes of the files in powers of 2, si displays the sizes of the files in powers of 10, so for example file2.txt and file5.txt contain exactly 1 000 000 000 and 2 000 000 000 bytes respectively, which is why their sizes are 1.0G and 2.0G, but not the same thing in the powers of 2 format, file2.txt is 954M and file5.txt is 1.9G
There is an other command that helps us for computing size of files, which is du
du stands for 'disk usage', used with -h option for human readable size format, and the name of the file for which we want to know the size
In the next tutorial, we will look more in depth into the options of du command, including size of directories, subdirectories, and the notion of blocks.
If you have any questions, leave them in the comments section below, and don't forget to share the tutorial with your friends if you found the tips presented here useful ;)
Happy Linux Learning :D