Regularly gathering file information is essential because you need to know which files are using up the most space and which ones are superfluous but taking up a lot of it before allocating additional space. We have a number of tools in Linux to check this. This article will examine many command-line techniques for determining the file size under Linux.

A binary file is a file with binary data that the computer’s processor can immediately execute. These files can be used to store software and other data that is not readable by humans. Here you will understand in detail how to find a file in Linux.

Different Ways to Find the File Size in Linux

In Linux, there are numerous techniques to determine the file size. I’ll go over some of the most popular techniques to find the file size in Linux in this response.

Using the ‘ls’ command:

One of the most used commands in Linux is the ‘ls’ command. It frequently lists the files and folders contained under a certain directory. The ‘ls’ command can also be used to determine a file’s size.

The ‘ls’ command should be used to determine the file size.

One of the most often used commands in Linux is probably the ‘ls’ command. Its definition is “to list,” as in “to list the files and folders from my current location.” It roughly corresponds to the DOS/Windows ‘dir’ command line option. The ‘ls’ man page will provide you access to a large range of parameters that you can use with this command. Let’s look at a couple of examples that display the file size.

ls -l <file>

To determine the size of the provided file, use the -l arguments.

ls -l *

The size of every file in the current directory can be obtained with the -l arguments.

ls -al *

To obtain the size of every file in the current directory, including hidden files, use the -al option.

ls -h -l <file>

The -h option displays the file sizes in human-readable form.

Using the ‘du’ command:

“Disc usage” is what the ‘du’ command stands for. It calculates how much disc space a file or directory takes up. To determine a file’s size, use the ‘du’ command.

Using the ‘du’ command, the following command will yield the file size:

du -h filename

The ‘-h’ option in this command denotes the “human-readable” format, and the ‘filename’ argument is the name of the file whose size you are interested in.

This command’s output will show the file size in a manner that is easy to understand, such as “50M” for 50 megabytes.

du -s <path>

Get the file or directory’s memory-allocated summary.

Using the ‘stat’ command:

‘stat’ is a command-line tool that shows the file or filesystem status. It can be used to show the file size along with other file properties.

The’stat’ command should be used to obtain the file size:

stat filename

The name of the file for which you wish to determine the size is provided as the ‘filename’ argument in this command.

This command’s output will show a number of file properties, including the file’s size in bytes.

Obtaining block sizes for files

For the current operation, the block argument can be used to provide a block size for du. Use the following command to determine the real sizes of the directories and files using a one-byte block size:

du --block=1

Use the following command to use a one-megabyte block size:

du -m
du -a

Beginning with the root directory, print information about directories and files in a tree format. As a result, the first files to be printed would be those in the root directory. Later, the root directories’ subdirectories’ files would be printed, and so forth.

du -d <depth>

Final Thoughts…

In this article, we looked at various command-line programs that may be used to determine the file size in operating systems that are similar to UNIX.

Before going on to the du command, which is used to calculate the disc utilization of specific files or directories, we went over the ls command and its various options. Hope you got it clear here and understand about Finding the Size of the Directory in Linux.