DF, DU, fdisk:linux Disk Management

Source: Internet
Author: User
Tags disk usage

Disk is a very important resource in Linux system, how to effectively manage it directly affects the performance 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.

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:

List 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%/no                       NE 0 0 0-/proc/dev/hda1 12048 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 6626 4 9876 56388 15%/var//Lists the file system type.   #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 takes up disk space #du–abk/mnt1       /mnt/cdrom1       /mnt/floppy3       /mnt//lists the disk space occupied by each directory, but does not list the space occupied by each file in detail # 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/saved-messages8192    Mail

3. fdisk

FDISK can partition a disk. 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 Option Commands 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, sectors/track, 522 cylindersunits = cylinders of 16065 * 512 = 82252 Bytes   Device Boot    Start       End    Blocks   Id  system/dev/hda1   *       522   3871665  linux/dev/hda2             1    321268+  Partition table entries is Not on 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   cylinder (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.

DF, DU, fdisk:linux Disk Management

Related Article

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.