DEV Community

David Cao
David Cao

Posted on • Updated on

4 ways to check file size in Linux

The file size is an important factor for many reasons. Whether you are trying to save space on your hard drive or just need to know the size of a file, it's helpful to know how to get this information in Linux.
In this blog post, we will discuss four different ways to get file size in Linux. We will also provide tips on how to use each method. Let's get started!

If you want to know the details about each command, you can check the following link.

4 ways to check file size in Linux

  1. Checking File Size with the “du” Command: The du command is a very useful tool for getting file size in Linux. To check file size, type "du -sh filename" and hit enter.
    This will display the size of the file, as well as any subdirectories within it. You can also use the du command to check directory size. To do this, type “du -sh directoryname” and hit enter.

  2. Checking File Size with the “ls” Command: The ls command is another way to get file size in Linux. To check file size, simply type "ls -l filename" and hit enter.
    This command will display the size of the file in a format that is easier to read.

  3. Checking File Size with the “stat” Command: The stat command is another way to get file size in Linux. To check file size, type "stat filename" and hit enter. This will display detailed information about the file, including its size.

  4. Checking File Size with the “find” Command: The find command is an advanced way of getting file size in Linux.
    To check file size, type "find filename -size n" and hit enter. This will display all files in the directory that are exactly n bytes in size.

Subscribe to HowToUseLinux!

Unlock the power of Linux with a click! Stay ahead of the curve with the latest trends, tools, and tricks in the Linux world. Subscribe now and transform your Linux journey!

We are also looking for writers.

These are just a few methods of getting file size in Linux. With these tips, you can easily get the information you need to manage your files and directories on Linux systems. Do you have any tips for getting file size in Linux? Let us know in the comments section below! Thanks for reading.

Top comments (0)