Regularly gathering file information is essential because you need to know which files are using up the most space. which ones are superfluous but take up a lot of it before allocating extra space. We have several 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. If one is looking for an efficiently managed system or server administration that works quickly needs to create new files 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.
1. 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.
2. 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.
3. 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 some 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. For adequate storage administration or system implementation research find the size of the directory in Linux.