Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands related to hard disk management commonly used in Linux

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what are the commands related to hard disk management commonly used in Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Df command

The df command is used to count the occupancy of partitions.

[root@localhost ~] # df-ahT

Options:

-a: displays special file systems, almost all of which are kept in memory. Such as proc, because it is mounted in memory, so the occupancy is 0.

-h: converted to a unit that humans are used to seeing (humanized display).

-T: there is an extra list of file system types.

Examples are as follows:

[root@localhost ~] # df-hT Filesystem Type Size Used Avail Use% Mounted on/dev/sda3 ext4 19G 2.2G 16G 13% / tmpfs tmpfs 495M 0495m 0% / dev/shm/dev/sdal ext4 190M 33M 147M 19% / boot

The results show that:

Filesystem: device file name.

Type: file system type.

Size: total partition size.

Used: occupancy size.

Avail: how much free?

Use%: utilization.

Mounted on: the mount point.

2. Du command

The du command is a command used to count directories or file sizes.

[root@localhost ~] # du [option] [directory or file name]

Options:

-a: displays the disk usage of each subfile. By default, only the disk usage of subdirectories is counted.

-h: use customary units to show disk usage, such as KB,MB or GB (humanized display).

-s: total occupancy is counted without listing the occupancy of subdirectories and subfiles.

(1) the ls or ll command to count the size of the directory is not accurate. Why?

We check the file size through the ls or ll command, and the directory is usually 0K or 4k or a multiple of 4K.

As shown below: except for the boot directory and the dev directory.

After I unzipped a 6.2m compressed package, the folder I went to also showed 4K.

As shown in the following figure:

The decompressed file is much smaller than the compressed file, which is obviously incorrect data.

This is obviously an unreasonable situation.

It indicates that there is a problem with the ls or ll command to calculate the file size, and the data for counting the directory size is not accurate.

The cause of this problem should start with zoning.

The directory has its own block block. The block block stores the file name and the corresponding I-node number, and the file name and I-node number of the files in the directory. The block block of the directory does not count the size of the files in the directory.

Record the file name of the directory and the corresponding I node number, and the file name and I node number of the file in the directory. If a block block can be installed, it is 4K. If it cannot be installed, it is stored in multiple block blocks, which is a multiple of 4K.

So execute the [root@localhost ~] # du-h httpd-2.2.9 command, and you can see the size of each file in the httpd-2.2.9 directory, and finally the size of the httpd-2.2.9 directory.

If you only need to look at the total size of the file, add the option s.

[root@localhost ~] # du-hs httpd-2.2.9

Explanation:

Why the boot directory is 1K size, because it was said earlier that the block block size is 1K, 2K, 4K (default), but boot is a separate partition, the default is 1KB.

Dev directory is a special hardware directory, which contains hard disk and other device information, which is special, so it is an exception.

(2) the difference between du command and df command

The du command is used to count the file size, which is accurate.

The df command is used to count the size of the space (both files and temporary files will be counted, and restart will be released), and the utilization of the partition is accurate (more specifically, the remaining space of the partition is accurate).

And if you can't restart the server at work, you can also release the space occupied by temporary files manually.

Sof I grep deleted: is the command to query the hidden status of files, to find out the files to be deleted, and then a process of manual kill is also possible.

This is extremely difficult to operate, the probability of error is high, and manual release is not recommended.

The loss caused by the planned restart of the Linux server is much smaller than that caused by the unexpected downtime or restart of the server.

3. Fsck file system repair command

This command is a file system repair command that comes with the Linux system.

This command is somewhat similar to the fact that the Windows system is not powered off properly (suddenly powered off) and will be prompted whether to scan the repair file the next time it is powered on.

Automatic repair command:

[root@localhost ~] # fsck-y / dev/sdb1

This command is automatically executed when the Linux system is powered on. If the file can be repaired through the fsck command, the boot auto-execution will be repaired, and if the file still reports an error after the Linux system starts, it is useless to execute the fsck command manually, and the repair is not good.

4. Display disk status dumpe2fs

Display disk status using the dumpe2fs command, execute dumpe2fs + partition number to view.

How to query the partition number, through the df-h command query, is very convenient.

The following is the result of executing the command:

There is a lot of information above, and if you only want to see the information in the super block (that is, the top part of the information), just add the-h option.

As follows:

[root@localhost ~] # dumpe2fs-h / dev/sda35, detailed time to view the file

Stat file name: the detailed time to view the file.

The result of executing the command is as follows:

As long as the information can be understood. Just get to know it.

6. Judge the file type

File file name: determining file type

Type command name: determine the command type

Determine the file type

If we judge a file, it will show that the file is an English document with ASCII code.

[root@localhost] # file anaconda-ks. Cfganaconda-ks. Cfg: ASCII English text

If we judge a directory, it will show that the file is a directory.

[root@localhost ~] # file 123Universe: directory

Determine the type of command

Commands in Linux system are divided into internal commands and external commands.

If you use the type command to determine the type of command, the location of the command indicates that it is an external command.

As follows:

[root@localhost ~] # type mkdirmkdir is / bin/mkdir

If you use the type command to determine the command type and display shell builtin (shell built-in command), it is an internal command.

As follows:

[root@localhost ~] # type cdcd is a shell builtin

If the command has an alias, use the type command to determine the command type, which displays the alias information for the command.

[root@localhost] # type lsls is aliased to' ls-- color=auto'

Tip: these two commands are generally used when writing scripts, and it is usually very convenient for us to distinguish between files and folders (with your eyes, ).

This is the end of the content of "what are the commands related to hard disk management commonly used in Linux". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report