How does linux view the total file size?

11-17-2023

Designed for programming, automatic code writing robot, free to open. This article mainly introduces the related knowledge about how to view the total file size in linux. The content is detailed and easy to understand, the operation is simple and quick, and it has certain reference value. I believe everyone will gain something after reading this article on how to view the total file size in linux. Let's take a look at it together.

Linux can view the total file size. Methods to check the total Size of the file: 1. Use the stat command, syntax stat file path, and the size field in the third line of the output result is the number of bytes in the file; 2. Use the wc command and syntax wc -c file path to output the number of bytes, words and lines in the specified file; 3. Use the du command, syntax du -h file path, and display the file size in customary units; 4, use the ls command, syntax ls -lh file path.

Operating environment of this tutorial: linux7.3 system and Dell G3 computer.

Linux can view the total file size.

There are many commands built into linux to check the file size. Let's take a look.

1. stat command stat command is used to display the status information of files. Grammar:

stat filepath

The output information of stat command is more detailed than that of ls command. The information that the stat command can view includes:

File: displays the file name.

Size: displays the file size.

Blocks: The total number of data blocks used by the file.

Ioblock: IO Block:IO size

Regular file: file type (regular file)

Device: device number

Inode:Inode number

Links: number of links

Access: permissions for files

Gid, Uid: Gid and Uid of file ownership.

Access time: indicates the last time we accessed the file (just accessed it, without changes).

Modify time: indicates the last time we modified the file.

Change time: indicates the last time we changed the file attributes, including permissions, size, attributes and so on.

Birth time: file creation time, crtime, but according to the investigation, this attribute linux has been abandoned, and the current status display results are all-

Example: View the size of the jdk-8u60-linux-x64.tar.gz file.

stat ~/Downloads/jdk-8u60-linux-x64.tar.gz

The Size field in the third line is the number of bytes in the file.

2. wc command The function of wc command is to count the number of bytes, words and lines in the specified file, and display and output the statistical results. If the file name is not specified or given as-,the wc command will read the data from the standard input device.

wc -c filename

Parameter -c: indicates the statistical character, because each character has one byte, so the number of bytes is obtained.

Example: View the size of the jdk-8u60-linux-x64.tar.gz file.

wc -c  ~/Downloads/jdk-8u60-linux-x64.tar.gz

3. The du command du is a command to count the disk space occupied by a directory or file.

Syntax counting in bytes

du -b filepath

Parameter -b: indicates counting in bytes.

Example:

du -b  ~/Downloads/jdk-8u60-linux-x64.tar.gz

Or directly get the file size that people can easily identify.

du -h filepath

-h: Use customary units to display disk occupancy, such as KB, MB or GB;

Example:

du -h  ~/Downloads/jdk-8u60-linux-x64.tar.gz

If you perform du on a directory, du will recursively list all files in the directory and display their sizes, and also display the sizes of all files in the directory. If we want to know the total space occupied by all files in a directory, execute:

Du destination directory -sh

-s, --summarize       display only a total for each argument

-h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)

4, ls command ls command, the abbreviation of list, is the most common directory operation command, its main function is to display the contents of the current directory. With some options, file sizes can be listed.

ls -l filepath

The fifth column of the output is the number of file bytes.

Example:

ls -l  ~/Downloads/jdk-8u60-linux-x64.tar.gz

ls -lh filepath

H stands for human, and add the -h parameter to get a human-friendly file size.

ls -lh  ~/Downloads/jdk-8u60-linux-x64.tar.gz[object Object]

The content of this article about how to check the total file size of linux is introduced here, thank you for reading! I believe that everyone has a certain understanding of how linux views the total size of files. If you want to learn more knowledge, please pay attention to the billion-speed cloud industry information channel.

Ask AI for details

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us