A file is a container that contains the specific data of a user on the hard disk. The size of every file is different and sometimes we need to make extra space for important files therefore one must delete large and unnecessary files. Therefore, before deletion, one must check the size of the files by using different methods used in Linux/ Ubuntu.

Check the Size of a File in Linux/Ubuntu

The files on Linux are properly structured in the form of a directory and subdirectory.  A person reaches that file by using commands in the terminal and finds the size of the file in different ways. To find the size of a file Linux gives different methods such as:

  • Check file size by using “du” command
  • Check file size by using “stat” command
  • Check file size by using “ls” command
  • Check file size by using “find” command
  • Check file size by using GUI Method

Method 1: Check File Size by Using “du” Command

This is the easiest way in Linux to find the size of any file. The first step is to open the terminal in your Linux then go to the directory where the file is located for which you want to find the size. The command used to find the file size is specifically given as:

du -h Test.odt

in the above command: 

  • du” full form is disk usage and is used to find the size of a file and directory.
  • -h” is used to display the size in readable form such as KB, MB.
  • Test.odt” is the file whose size is to be found.

Now execute the command stated command to get the size of the selected file.

Check File Size By Using du -sh Command

The final command used to find the file size is given as:

du -sh Test.odt

In the above command 

  • -sh” is used to find the size of a file in the subdirectory.

Method 2: Check File Size by Using “stat” Command

This is another way to find the size of the file, a detailed view of the file will be shown after following this command. This command gives the information about the file system and file. Now type the command “stat file name” and press enter this will show you the size of the file:  

The command used to find the file size is specifically given as:

stat Test.odt

In the above command 

  • stat” command gives information about the file system and file,  and is used to find the detailed view of a file such as its size, its read and write capability, when that file was created, and all other information.

Method 3: Check File Size by Using “ls” Command

The most important and widely used command to find the size of any file is “ls” command. This command gives the size of a file in readable format. Now type the command ls -lh file name and press enter this will show you the size of the file:

The final command implemented to find the size is given as

ls -lh Test.odt

In the above command 

  • ls” provides the list of files in a directory.
  • -lh” provides the file size in a readable format.

Check File Size By Using ls -sh Command

The final command used to find the file size is given as:

ls -sh Test.odt

In the above command

  •  “-sh” is used to find the size of a file in the subdirectory.

Check File Size By Using ls -l Command

The final command used to find the file size is given as:

ls -l Test.odt

In the above command 

  • -l” is used to find all information about the file such as its size, its read and write ability, and other information.  

Check File Size By Using ls -l –block- size Command

The final command used to find the file size is given as:

ls -l -block -size

In the above command 

  • –block -size” is used to show the file size in MB.

Check File Size By Using ls -sh * Command

The final command used to find the file size is given as: 

ls -sh *

The above command is used to find the size of all files in the current directory. In the above command 

  • -sh *” provides the size of every file found in the directory.

Check file size by Using “find” Command

The “find” is used to check for the file of known size in the Linux/Ubuntu terminal. In other words, you use this command to check for a file of a specific size. For example, if you know the size of the file is 8.0k but not the name of the file then use this command to find it. The command to be executed for this purpose is given as

find . -size 8k

Method 4: Check file size by using GUI Method

This is the easiest way to find the size of a file in Linux. Just like the window you need to use the GUI panel to find the file size. The steps involved in finding size by GUI method are given as

Step 1: Right-click on the file you want to find the size, and then from the dropdown options click on the Properties.

Step 2: After clicking on the Properties a screen will appear which shows the size of the file as shown in the figure below.  

Conclusion

To find the size of a file in Linux different methods are available such as checking file size by using “du” command, checking file size by using “stat” command, checking file size by using “ls” command, and checking file size by using the GUI Method. Among all of these methods, the easiest one is to check the file size by using the GUI method. In this method, you right-click on the file you want to find the size and then click on the properties and it shows you the size of a file.