Du, DF, fdisk, mkfs. ext3 command details

Source: Internet
Author: User
Tags disk usage

1. detailed usage of the du command

Common commands: [B] du [/B]-

Query the disk space used by an archive or directory

A: displays the disk space occupied by all directories and each file in the second directory.

B: The size is represented by bytes (the default value is K bytes)

C: add the total value (default)

S: only display the total size of each file

X: only calculate the files of the same file system.

L: Calculate the size of all files


The command du can display the disk space occupied by all files in each directory in the unit of subdirectories in the specified directory. Use the-H parameter to display the human-readable format. For example:

# Du-H/etc

104 K/etc/defaults

6.0 K/etc/X11

When viewing the usage of the Directory, we can export the output results to the sort command for sorting to know which file has used the most space:

# Du/etc | sort-Nr | more



318/etc/rc. d


2. Detailed DF command usage

Common commands: DF-Hi

A: displays the disk usage of all file systems and partitions.

I: displays the I-nodes usage.

K: The size is represented by K (default)

T: displays the disk usage of all partitions in a file system.

X: displays the disk usage of all partitions of a file system.

T: displays the file system name of each partition.


The command DF can display the maximum available space and usage of all file systems. See the following example:

# DF-H

Filesystem size used avail use % mounted on


37g 3.6g 32G 11%/

/Dev/sda1 99 m 12 m 83 m 13%/boot

Tmpfs 506 M 0 506 m 0%/dev/SHM


3. How to Use fdisk partitions in Linux


1. fdisk introduction;

Fdisk-Partition Table Manipulator for Linux, translated into Chinese means the disk partition table operation tool; I did not translate very well and did not read the Chinese documentation; in fact, it is actually a partition tool;

Fdsik can divide disks into Several partitions and specify the partition file system for each partition, for example, Linux, FAT32, Linux, Linux swap, fat16, and file systems of Unix-like operating systems. Of course, when we use fdisk to operate partitions on disks, it is not an end point, we need to format the required file system for the partition so that a partition can be used. This is similar to fdisk in DOS;


2. reasonably plan your hard disk partition;

Before partitioning, we need to understand the theory of Hard Disk partitioning, such as the calculation of hard disk capacity and partition size; for how to plan partitions for a hard disk, please refer to the following documents. Thank you;

Rational Planning of your hard disk partition


3. fdisk-l view the hard disk and partition information;

Through rational planning of your hard disk partitions, we know that the total number of primary partitions (including extended partitions) cannot exceed four, nor can we enclose extended Partitions between primary partitions. According to this principle, it is easier to divide hard disk partitions and reduce unnecessary troubles in the future;

1. Use fdisk-L to view the number of hard disks mounted to the machine and the partition information;

Total disk capacity = total capacity of the primary partition (including extended partitions)

Extended partition capacity = total capacity of logical partitions

2. Description of some fdisk-L values;

Disk/dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 Cylinders

Units = cylinders of 16065*512 = 8225280 bytes

The hard disk is 80 GB, with 255 magnetic surfaces; 63 sectors; 9729 magnetic columns; the capacity of each cylinder (magnetic column) is 8225280 bytes = 8225.280 K (about) = 8.225280 M (about );

Partition sequence boot starts to terminate capacity partition type ID partition type

Device boot start end blocks ID system

/Dev/hda1*1 765 6144831 7 HPFs/NTFS

/Dev/hda2 766 2805 16386300 C w95 FAT32 (LBA)

/Dev/hda3 2806 9729 55617030 5 extended

/Dev/hda5 2806 3825 8193118 + 83 Linux

/Dev/hda6 3826 5100 10241406 83 Linux

/Dev/hda7 5101 5198 787153 + 82 Linux swap/Solaris

/Dev/hda8 5199 6657 11719386 83 Linux

/Dev/hda9 6658 7751 8787523 + 83 Linux

/Dev/hda10 7752 9729 15888253 + 83 Linux


Hard Disk Partition representation: in Linux, HD * X or SD * X is used, where * represents a, B, c ...... ...... Numbers 1, 2, 3, and so on ...... ...... Hdds are mostly IDE hard disks; SD is mostly SCSI or mobile storage;

Boot: indicates the boot partition. In the preceding example, hda1 is the boot partition;

Start (start): indicates that a partition starts from X cylinder (magnetic column;

End: indicates that a partition ends with y cylinder (magnetic column;

ID and system indicate the same meaning. ID does not seem intuitive. We need to specify the ID to confirm the partition type when fdisk is a partition. For example, if the ID is 7, NTFS is used; this must be specified through the T function in fdisk. The following parts will be mentioned;

Blocks; the value of a partition capacity comes from the following formula;

Blocks = (end value of the corresponding partition-start value of the corresponding partition) Capacity of x unit cylinder (magnetic column)

So let's calculate the size of the blocks in hda1:

Hda1 blocks = (765-1) x8225.280 = 6284113.92 K = 6284.113.92m

Note: The conversion unit is counted from the 10th digit provided by the hard disk manufacturer. If the unit is measured in binary format of the operating system, the partition capacity should be less, the obtained value is roughly the same as the value of/dev/hda1 we can see through fdisk-L. Because the conversion method is different, it is impossible to be as accurate as possible; in addition, some loss occurs during partitioning, and sometimes large or small;

When we look at the partition size or file, we still use decimal to calculate it more intuitively. The calculation method is that byte pushes the three decimal places forward to K, and the value in K units pushes the three decimal places forward to M, M is pushed forward to the decimal point ...... ...... Generally, it cannot be much worse;


4. fdisk operations on hard disks and partitions enter the fdisk operation phase;

We can partition the hard disk on the premise that you have understood fdisk-L; through fdisk-l, we can find the number of all hard disks and device names on the machine; for example, in the above example, we can see two devices:/dev/hda and/dev/SDA;

The command format for fdisk hard disk operation is as follows:

[Root @ localhost] # fdisk Device

For example, we know the/dev/hda or/dev/SDA device through fdisk-L. If we want to add or delete some partitions, we can use

[Root @ localhost] # fdisk/dev/hda


[Root @ localhost] # fdisk/dev/SDA

Note: In the following example, we will use the/dev/SDA device as an example to explain how to use fdisk to add or delete partitions;

1. Description of fdisk;

When you access the corresponding device through the fdisk device, you will find the following prompt: Take the fdisk/dev/SDA device as an example, the same as below;

[Root @ localhost] # fdisk/dev/SDA

Command (M for help): press m here to output help;

Command action

A toggle a bootable flag

B edit BSD disklabel

C toggle the DOS compatibility flag

D delete a partition note: this operation deletes a partition;

L List known partition types Note: l lists the partition types for us to set the corresponding partition types;

M print this menu Note: m lists help information;

N Add a new partition Note: Add a partition;

O create a new empty DOS partition table

P print the Partition Table Note: P lists partition tables;

Q quit without saving changes Note: Do not save and exit;

S create a new empty sun disklabel

T change a partition's System ID Note: T changes the partition type;

U change display/entry units

V verify the Partition Table

W write table to disk and exit note: Write the Partition Table to the hard disk and exit;

X extra functionality (experts only) Note: extends the application and expert functions;

In fact, we only use Chinese annotations. Other functions are not commonly used (Oh, I will not use them, or we will sell them out early). x extension functions are not commonly used; generally, you only need to know d l m p q t w;

The following is a detailed description of instance operations. If there are no examples, you cannot understand them;

2. List the partitions of the current hard disk. Use p;

Command (M for help): p

Disk/dev/SDA: 1035 MB, 1035730944 bytes

256 heads, 63 sectors/track, 125 Cylinders

Units = cylinders of 16128*512 = 8257536 bytes

Device boot start end blocks ID system

/Dev/sda1 1 25 201568 + C w95 FAT32 (LBA)

/Dev/sda2 26 125 806400 5 extended

/Dev/sda5 26 50 201568 + 83 Linux

/Dev/sda6 51 76 200781 83 Linux

Then we use the T command to change the partition type;

Do not forget to save and exit;


5. Format and load partitions;

A prompt is given first. Use mkfs. BFS mkfs. ext2 mkfs. JFS mkfs. msdos mkfs. vfatmkfs. cramfs mkfs. ext3 mkfs. minix mkfs. reiserfs mkfs. XFS and other commands to format the partition. For example, if I want to format sda6 as the ext3 file system, enter;

[Root @ localhost] # mkfs. ext3/dev/sda6

If I want to load sda6 to the current system to access files, there should be a mount command, but first you must create a mount directory; for example,/mnt/sda6;

[Root @ localhost] # mkdir/mnt/sda6

[Root @ localhost] # Mount/dev/sda6/mnt/sda6

[Root @ localhost] # DF-lH

Filesystem capacity in use available % mount point

/Dev/hda8 11g 8.4g 2.0g 81%/

/Dev/SHM 236 M 0 236 m 0%/dev/SHM

/Dev/hda10 16g 6.9g 8.3g 46%/mnt/hda10

/Dev/sda6 191 M 5.6 m 176 m 4%/mnt/sda6

In this way, we can access the/mnt/sda6 directory and then access the file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.