Linux disk management: df, du, fdisk, mkfs, fsck

  

Linux disk management good or bad management is directly related to the performance of the entire system. Linux disk management commonly uses several commands for df, du, fdisk, mkfs, and fsck. 1.df: List the overall disk usage of the file system 2.du: Check disk space usage 3.fdisk: for disk partition 4.mkfs: format 5.fsck: disk check

df< Br>

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.

Syntax: df [-ahikHTm] [directory or file name]

Options and parameters: 1.-a : List all file systems, including system-specific file systems such as /proc ;2.-k: display each file system with KBytes capacity; 3.-m: display each file system with MBytes capacity; 4.-h: display itself in GBytes, MBytes, KBytes and other formats that people can easily read; 5.-H: Replace the M=1024K carry mode with M=1000K; 6.-T: Display the file system type, together with the filesystem name of the partition (for example, ext3); 7.-i: No hard disk capacity, And the number of inodes is displayed

Instance 1 lists all the 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 have any options, then by default all files in the system (excluding filesystems and swaps in special memory) will be 1 Kbytes. Come list!

Instance 2 displays the capacity results in an easy-to-read 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

Instance 3 will all special file formats and names in the system Listed as [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 4559108 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

Instance 4 displays the available disk capacity under /etc in an easy-to-read 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 also looks at the usage space, but with df So the difference is Linux du command is the disk space the files and directories used to view, or df command and there are some differences, introduce Linux du command here. Syntax: du [-ahskm] File or directory name

Options and parameters: 1.-a : List all file and directory capacities, because the default is only to count the amount of files under the directory. 2.-h: Displayed in a more readable capacity format (G/M); 3.-s: Lists the total amount, not the capacity of each individual directory; 4.-S: No Include totals under subdirectories, a little different from -s. 5.-k: List the capacity display in KBytes; 6.-m: List the capacity display in MBytes;

Instance 1 lists all file sizes in the current directory [root@www ~]# du8 . /test4 <==Each directory will be listed as 8 ./test2.... omitted in the middle ....12 ./.gconfd <== directory containing hidden files 220 . <== this directory (. The total amount occupied

Direct input du When no option is added, du will analyze the hard disk space occupied by the files and directories in the current directory.

Instance 2 also lists the file size [root@www ~]# du -a12 ./install.log.syslog <== has a list of files 8 ./.bash_logout8 ./test48 . /test2.... omitted in the middle....12 ./.gconfd220 .

Instance 3 checks the capacity occupied by each directory under the root directory [root@www ~]# du -sm /*7 /bin6 /boot..... omitted in the middle....0 /proc..... omitted in the middle....1 /tmp3859 /usr <== The system is the biggest in the beginning! 77 /var

The wildcard * is used to represent each directory. Unlike df, the du command actually goes directly to the file system to search all file data.

fdisk

fdisk is a Linux disk partition table manipulation tool. Syntax: fdisk [-l] Device Name

Options and Parameters: 1.-l: Output all partition contents of the device connected. If only fdisk -l is present, the system will list the partitions of the devices that can be found in the entire system.

Instance 1 lists all partition information [root@AY120919111755c246621 tmp]# fdisk -l

Disk /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 Blocks Id System /dev/xvda1 * 1 2550 20480000 83 Linux/dev/xvda2 2550 2611 490496 82 Linux swap /Solaris

Disk /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 size (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 out the disk where the root directory of your system is located, and check the related information in the hard disk [root@www ~]# df /<==Note : The focus is on finding the disk file name. Ilesystem 1K-blocks Used Available Use% Mounted on/dev/hdc2 9920624 3823168 5585388 41% /

[root@www ~]# fdisk /dev/hdc <==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 be in certain setups cause problems with:1) software that runs at boot time (eg, old versions of LILO 2) booting and partitioning software from other OSs(eg, DOS FDISK, OS/2 FDISK)

Command (m for help): <==waiting for your input!

When you type m, you will see the following commands to introduce Command (m for help): m <== After entering m, you will see the following commands. Command actiona toggle a bootable flagb edit bsd Disklabelc toggle the dos compatibility flagd delete a partition <==delete a partitionl list known partition typesm print this menun add a new partition <==add a partitiono create a new empty DOS partition tablep print the partition table <== Display partition table q quit without saving changes <==do not leave the fdisk program s create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exit <= = Write the action just to the split table x extra functionality (experts only)

Press q when leaving fdisk, then all actions will not take effect! Conversely, pressing w is the meaning of the action. Command (m for help): p <== Here you can output the current state of the disk

Disk /dev/hdc: 41.1 GB, 41174138880 bytes <==The file name and capacity of this disk is 255 heads, 63 sectors/track, 5005 cylinders <==head, sector and cylinder size

Copyright © Windows knowledge All Rights Reserved