DF, DU, fdisk:linux Disk Management command collation

Source: Internet
Author: User
Tags disk usage

Experience of using DF, DU, fdisk:linux Disk Management kick

Disk is a very important resource in Linux system, how to effectively manage it directly affects the performance of the whole system. In commonly used commands, DF is used to check file system disk occupancy, du checks disk space usage, and fdisk is used for disk partitioning, which is the author's more commonly used three commands, share some of this experience.


"51CTO exclusive feature" Disk is a very important resource in Linux system, how to effectively manage it is directly related to the performance problem of the whole system. For Linux Disk Management There are a few learning and experience friends who should be aware of the three common commands for DF, Du, and fdisk: DF is used to check file system disk usage, du checks disk space usage, and fdisk is used for disk partitioning. These three tools are the tools I used in Linux Disk Management, and share some of the experience with you.

Author: Li Yang (blog), PhD graduated from the CAS Institute of Computing. For more than more than 10 years, he has been engaged in the research and development of computer network information security, presided over and participated in many national key projects as well as information security system and enterprise information security system research and development work. With Linux system application, management, security and core research and development experience, good at network security technology, protocol analysis, Linux system security technology, Linux system and network management, Linux kernel development.

1. Df

The DF command can get information about how much space the hard disk is taking up, how much space is left, and it can also show the usage of all file systems on the I node and disk blocks.

The DF command has the following meanings for each option:

-A: Displays disk usage for all file systems, including 0 blocks of file systems, such as the/proc file system.  -K: Displayed in K-byte units.  -I: Displays the I node information, not the disk block.  -T: Displays disk space usage for each of the specified types of file systems.  -X: Lists disk space usage that is not a specified type of file system (as opposed to the T option). -T: Displays the file system type.

Let's look at the example of using the DF command first:

Lists disk space usage for each file system #dffilesystem           1k-blocks       used   available use% mounted on/dev/hda5                381139      332921     28540  93% //dev/hda1                 46636       6871     37357  16% /boot/dev/hda3              10041144   6632528    2898556  70% /homenone                     127372         0     127372   0% /dev/shm/dev/hda2              27474876  24130460   1948772  93% /usr/dev/hda6                256667     232729     10686  96% /var

The 1th column is the pathname of the device file that represents the file system (typically the partition on the hard disk), the 2nd column gives the number of data blocks (1024 bytes) that the partition contains, and the 3rd, 4 columns indicate the number of data blocks used and available respectively.

Users may wonder, 3rd, that the sum of 4 column blocks is not equal to the number of blocks in the 2nd column. This is because each of the default partitions leaves a small amount of space for the system administrator to use. The administrator can log in and leave the workspace required to resolve the problem, even when the normal user space is full. The use% column in the list represents the percentage of normal user space used, and if this number reaches 100%, the partition still leaves room for the system administrator to use.

Finally, the mounted on column represents the mount point of the file system.

Lists the I node usage for each file system. #df  -iaFilesystem            Inodes    IUsed   IFree IUse% Mounted on/dev/hda5               98392   23919    74473   25% /none                        0       0        0    -  /proc/dev/hda1               12048       38   12010    1% /bootnone                        0        0       0    -  /dev/pts/ dev/hda3            1275456  355008   920448   28% /homenone                    31843       1    31842    1% /dev/shm/dev/hda2             3489792  133637 3356155    4% /usr /dev/hda6              66264     9876   56388   15% /var //lists the types of file systems. #df  -TFilesystem    Type   1k-blocks       used available use% mounted on/dev/hda5     ext3      381139     332921     28540  93% //dev/hda1      ext3       46636      6871      37357  16% /boot/dev/hda3     ext3     10041144   6632528   2898556  70% /homenone          tmpfs      127372          0    127372   0% /dev/shm/dev/hda2      ext3    27474876  24130460    1948772  93% /usr/dev/hda6     ext3       256667     232729     10686  96% /var2 

2. Du

Du's English literal is "disk usage", meaning to show the use of disk space, the size of the statistics directory (or file) of disk space. The function of this command is to step into each subdirectory of the specified directory and show that the directory occupies the file system data block (1024 bytes). If the specified directory is not given, the current directory is counted.

The various options for the DF command have the following meanings:

-S: Only the total number of data blocks that are occupied for each names parameter is given. -A: Recursively displays the number of blocks of data in each file and subdirectory in the specified directory.  If you do not specify-s and do not specify-a, only the number of disk blocks that are in each directory in names and the subdirectories in it are displayed.  -B: The disk space usage is listed in bytes (the system defaults to K bytes).  -K: Lists disk space usage in 1024-byte units.  -C: Finally, add a total (system default setting).  -L: Calculates all file sizes, and computes multiple times for hard-linked files. -X: Skipping directories on different file systems is not counted.

The following examples illustrate the use of the du command:

View the/MNT directory that consumes disk space #du–abk/mnt1/mnt/cdrom1/mnt/floppy3/mnt//lists the disk space occupied by each directory, but does not detail the space occupied by each file #du3684 ./log84./libnids-1.17/doc720./libnids-1.17/src32./libnids-1.17/samples1064./libnids-1.174944.

The 1th column in the output manifest is the disk space capacity in blocks, and the 2nd column lists the directory names that use these spaces in the directory.

This can be a very long list, sometimes it only takes a total. You can then add the-s option to the du command to get the total:

#du –s/mnt 3/mnt//lists the space occupied by all files and directories (using the A option) and calculates the size in bytes (using the B option) #du–ab/root/mail6144 mail/sent-mail1024 mail/s aved-messages8192 Mail

3. fdisk

Fdisk divides the disk partitions. The following is a procedure for partitioning a disk using the FDISK command:

#fdisk  /dev/had    //use/dev/had as the default partition device command  (M FOR HELP):  m   //Select command Options command action   a   toggle a bootable  flag   b   edit bsd disklabel   c    toggle the dos compatibility flag   d   delete a  Partition   l   list known partition types   m    print this menu   n   add a new  partition   o   create a new empty dos partition  table   p   print the partition table   q    quit without saving changes   s   create a  New empty sun diSklabel   t   change a partition ' s system id    u   change display/entry units   v   verify  The partition table   w   write table to disk and  exit   x   extra functionality  (experts only)

The user prompts to type "M" to display a description of each parameter of the FDISK command.

Fdisk has many parameters, but only a few of them are used frequently.

In the Linux partitioning process, the disk partition table information is typically displayed by the P parameter, and then the future partitions are determined based on the information. As shown below:

 disk /dev/sda: 4294 mb, 4294967296 bytes255 heads, 63 sectors/ track, 522 cylindersunits = cylinders of 16065 * 512 =  8225280 bytes   device boot    start        End    Blocks   Id  System/dev/hda1    *        41       522    3871665   83  Linux/dev/hda2              1        40     321268+  82  Linux swap Partition table entries are  not in disk ordercommand  (m for help): 

If you want to completely change the partition format of the hard disk, you can delete the existing hard disk partition one by one by the D parameter. After deletion, the new partition can be added by the n parameter. When "n" is pressed, you can see the following:

Command (M for help): Ncommand action E Extended P primary partition (1-4) p Partiton Number (1-4): 1 First CY Linder (1-1023): 1 Last cylinder or + size or +sizek or + Sizem (1-1023): +258m

Choose whether to create a new partition type, a primary or an extended partition, and select either P or E. Then the size of the partition is set.

Note that if you have an extended partition on your hard disk, you can only increase the logical partition and not increase the extended partition.

When adding partitions, its type is the default Linux Native, if you want to change some of the partitions to other types, such as Linux swap or FAT32, can be changed by the command T, when the "T" to change the partition type, the system will be prompted to change which partition, and change why type (if you want to know what type of partition the system supports, type L) as follows:

Command (M for help): Tpartition number (1-4): 1Hex code (type L to list codes): 82Changed system type of partition 1 to 8 2 (Linux Swap)

After you have changed the partition type, you can press "W" to save and exit. If you do not want to save, then you can choose "Q" to exit directly, as follows:

Command (M for help): W

By doing so, you can successfully partition the partitions as needed.

"51cto.com exclusive feature, reproduced please specify the original author and source." 】

"Editor's recommendation"

    1. Linux system Monitoring disk I/O Chapter

    2. UNIX Operating system Disk Management

    3. Quota command detailing Linux disk quotas

This article is from the "Mr_computer" blog, make sure to keep this source http://caochun.blog.51cto.com/4497308/1722886

DF, DU, fdisk:linux Disk Management command collation

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.