One of the most asked questions about files in Linux is how can I list file sizes in different formats? In this post, we will look at different commands to get file sizes.
ls command is a primary command to list and get information about files and directories in Linux. ls command can be used with -l parameter to get the size of files.
$ ls -l nmap-7.31.tgz
We listed file nmap-7.31.tgz file size in byte but we can make the size information more readable by using -h option.
$ ls -lh nmap-7.31.tgz
du command is used to get disk usage.
$ du nmap-7.31.tgz
We have simply listed the file without providing any parameter. Provided size is in KB. If we want to get a human-friendly result we can use the following.
$ du -h nmap-7.31.tgz
Stat command is used to get file system-related information about files and directories. Using stat with filename parameter will provide size information in byte mode too.
$ stat nmap-7.31.tgz