Teach you to play Linux – disk management

The quality of Linux disk management is directly related to the performance of the whole system.


DF command parameter function: check the disk space occupation of the file system. You can use this command to get information about how much space the hard disk is occupied and how much space is left.


DF [- ahikhtml] [directory or filename]

Options and parameters:

-A: list all file systems, including system specific / proc and other file systems; – K: display file systems with Kbytes capacity; – M: display file systems with Mbytes capacity; – H: display file systems in Gbytes, Mbytes, Kbytes and other formats that are easy for people to read by themselves; – H: replace M = 1024k carry mode with M = 1000K; – t: display file system type, together with The filesystem name of the partition (for example, ext3) is also listed; – I: not the hard disk capacity, but the number of inodes

Example 1

List all file systems in the system!

[root@www ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/hdc2 9920624 3823112 5585444 41% //dev/hdc3 4956316 141376 4559108 4% /home/dev/hdc1 101086 11126 84741 12% /boottmpfs 371332 0 371332 0% /dev/shm

Under Linux, if DF does not add any options, all the file systems (excluding special memory and swap) in the system will be listed with the capacity of 1 Kbytes by default!

Example 2

Display capacity results in readable capacity format

[root@www ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/hdc2 9.5G 3.7G 5.4G 41% //dev/hdc3 4.8G 139M 4.4G 4% /home/dev/hdc1 99M 11M 83M 12% /boottmpfs 363M 0 363M 0% /dev/shm

Example 3

List all special file formats and names in the system

[root@www ~]# df -aTFilesystem Type 1K-blocks Used Available Use% Mounted on/dev/hdc2 ext3 9920624 3823112 5585444 41% /proc proc 0 0 0 - /procsysfs sysfs 0 0 0 - /sysdevpts devpts 0 0 0 - /dev/pts/dev/hdc3 ext3 4956316 141376 45 59108 4% /home/dev/hdc1 ext3 101086 11126 84741 12% /boottmpfs tmpfs 371332 0 371332 0% /dev/shmnone binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_miscsunrpc rpc_pipefs 0 0 0 - /var/lib/nfs/rpc_pipefs

Example 4

Display the available disk capacity under / etc in a readable capacity format

[root@www ~]# df -h /etcFilesystem Size Used Avail Use% Mounted on/dev/hdc2 9.5G 3.7G 5.4G 41% /du


The Linux Du command is also used to view the space used, but different from the DF command is that the Linux Du command is used to view the space used by files and directory disks, or it is different from the DF command. The Linux Du command is introduced here.


Du [- ahskm] file or directory name

Options and parameters:

-A: list all the file and directory capacities, because by default, only the number of files under the directory is counted. -H: display in g / M format; s: list the total amount instead of the occupied capacity of each directory; s: exclude the total under subdirectories, which is a little different from – S. -K: display capacity in Kbytes; – M: display capacity in Mbytes;

Example 1

List only the capacity of all folders in the current directory (including hidden folders):

[root @ www ~] ා du8. / test4 & lt; = = each directory will be listed 8. / test2.... omit in the middle.... 12. / gconfd & lt; = = the total amount of the directory including hidden files 220. & lt; = = this directory (.)

If you enter Du directly without any options, Du will analyze the hard disk space occupied by the files and directories in the current directory.

Example 2

List the capacity of the file as well

[root @ www ~] ා Du - A12. / install. Log. Syslog & lt; = = the list with files is 8. / bash ﹣ logout8. / test48. / test2.... omitted in the middle.... 12. / gconfd220

Example 3

Check the capacity of each directory under the root directory

[root @ www ~] (DU - SM / * 7 / bin6 / boot..... Middle ellipsis.... 0 / proc..... Middle ellipsis.... 1 / tmp3859 / usr & lt; = = he is the biggest one in the initial stage of the system! 77 /var

The wildcard * represents each directory.

Unlike DF, the Du command actually searches all the file data directly in the file system.


Fdisk is a partition table operation tool of Linux.


Fdisk [- l] device name

Options and parameters:

-L: output all partition contents of the device connected later. If there is only fdisk-l, the system will list the partition of devices that can be found in the whole system.

Example 1

List all partition information

[root@AY120919111755c246621 tmp]# fdisk -lDisk /dev/xvda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000 Device Boot Start End B locks Id System/dev/xvda1 * 1 2550 20480000 83 Linux/dev/xvda2 2550 2611 490496 82 Linux swap / SolarisDisk /dev/xvdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O si ze (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x56f40944 Device Boot Start End Blocks Id System/dev/xvdb2 1 2610 20964793+ 83 Linux

Example 2

Find the disk where the root directory in your system is located, and check the relevant information in the hard disk

[root @ www ~] ා DF / & lt; = = note: the key is to find out the disk file name. Filesystem 1K blocks used available use% mounted on / dev / hdc2 9920624 3823168 5585388 41% / [root @ www ~] ා fdisk / dev / HDC & lt; = = look carefully, don't add numbers! The number of cylinders for this disk is set to 5005. There is nothing wrong with that, but this is larger than 1024, and could in certain settings cause problems with: 1) software that runs at boot time (e.g., old versions of Lilo) 2) booting and partitioning software from other OSS (e.g., DOS fdisk, OS / 2 fdisk) command (m for help): & lt; = = wait Your input!

After entering m, you will see the following command introduction

Command (m for help): M & lt; = = after entering m, you will see the following command introduction command action a toggle a bootable flag B edit BSD disklabel C toggle the DOS compatibility flag D delete a partition & lt; = = delete a partition l list known partition types m print this menu n add a new partition ≪ = = add a new partition o create a new empty DOS partition table P print the partition table & lt; = = show the partition table Q quite without saving change S & lt; = = do not save to leave fdisk programs create a new empty sun diskable t change a partition's system ID u change display / entry units V verify the partition t Able w write table to disk and Exit & lt; = = write the just action to the partition table x extra functionality (experts only)

Press Q when leaving fdisk, then all actions will not take effect! On the contrary, pressing w means the action takes effect.

Command (m for help): P & lt; = = here you can output the current disk status disk / dev / HDC: 41.1 GB, 41174138800 bytes & lt; = = the file name and capacity of this disk 255 heads, 63 sectors / track, 5005 cylinders & lt; = = the size of heads, sectors and pillars units = cylinders of 16065 * 512 = 8225280 bytes & lt; = = the size of each pillar device boot start End Blocks Id System/dev/hdc1 * 1 13 104391 83 Linux/dev/hdc2 14 1288 10241437+ 83 Linux/dev/hdc3 1289 1925 5116702+ 83 Linux/dev/hdc4 1926 5005 24740100 5 Extended/dev/hdc5 1926 2052 1020096 82 Linux swap / Solaris ා device file name start area no start column end column 1K capacity disk partition slot system command (m for help): Q

Want to leave without saving? Just press q! Don’t just press w!

Use p to list the partition table information of the current disk. The top half of this information displays the status of the whole disk.


Linux should learn this is a high-quality self-study course of Linux technology jointly written by senior operation and maintenance expert Liu Tan and many red hat Architects (rhca) in China based on the latest rhel7 system, which is extremely suitable for Linux technology introductory course or lecture auxiliary textbook. Won the IT book sales champion of double 11 and double 12 shopping carnival, and the fastest-growing technical books in 2017 and 2018, you can buy them after JD, Dangdang, Amazon and tmall search the titles, or add teacher Liu Trent’s wechat communication and learning (press and hold the figure below for 3 seconds to scan automatically)~

Teacher Liu Trent QQ: 5604922

☑ & nbsp; Linux technology exchange group: 2265381 (new group, hot group…)

Official website: www.linuxprobe.com

☑ online learning of books (better effect of online reading on computer):

第0章 咱们先来谈谈学习方法和红帽系统。

This is how to learn Linux is a technical book written based on the latest Linux system for zero base readers. Starting from the basic knowledge of Linux, then gradually improve the difficulty of content, explain the working principle and configuration mode of various services in Linux system in detail to match the requirements of real production environment for operation and maintenance personnel, and highlight the practicality of content. If you want to learn Linux system, you can click the “read the original” button to learn about this book. At the same time, this book is also suitable for professional operation and maintenance personnel to read, as a very valuable reference tool book!


电子邮件地址不会被公开。 必填项已用*标注