For file storage management, system resource monitoring, or curiosity about a specific file's size, quick retrieval of file size in bytes on a Linux system is a valuable skill. This tutorial provides 2 methods how to get file size in bytes on Linux.
Method 1 - wc command
wc command, which stands for word count, is a versatile tool that can be used to count characters, words, and lines in a file. When combined with the
-c option, it counts the number of bytes in the specified file.
For example, to find the size of a file named
test.txt, we can run the command:
wc -c < test.txt
Method 2 - stat command
stat command is another powerful utility that provides detailed information about a file, including its size. When combined with the
-c option and the format specifier
%s, it displays only the size of the file in bytes.
For example, to get the size of
test.txt, execute the following command:
stat -c %s test.txt