Viewing disk space on Linux system

Time:2022-3-23

1、 DF command;

DF is from coreutils software package,systeminstallWhen, it comes with its own; Through this command, we can view the usage of the disk and the filessystemMounted position;

give an example:

[[email protected] beinan]# df -lh

Filesystem capacity used% mount point available

/dev/hda8 11G 6.0G 4.4G 58% /

/dev/shm 236M 0 236M 0% /dev/shm

/dev/sda1 56G 22G 35G 39% /mnt/sda1

As we can see,systeminstallIn / dev / hda8; There is also a 56g disk partition / dev / sda1 mounted in / MNT / sda1;

For other parameters, please refer to man DF

2、 Fdsik

Fdisk is a powerful diskoperationTool, from util-linuxFor the software package, we only talk about how to view the disk partition table and partition structure; Parameter – L, through the – L parameter, the partition of all hard disks in the machine can be obtained;

[[email protected] beinan]# fdisk -l

Disk /dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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 7751 39728745 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

In the above blocks, it refers to the size of the partition. The unit of blocks is byte, which can be converted into M. for example, if the size of the first partition / dev / hda1 is converted into m, it should be 6144831 / 1024 = 6000m, that is, about 6G. In fact, it is not so troublesome. Take a rough look at moving the decimal point forward by three digits to know the approximate volume;

File represented by systemsystemFor example, / dev / hda1 is in NTFS format/ Dev / hda2 indicates a file in FAT32 formatsystem;.

In this example, we should pay special attention to the / dev / hda3 partition, which is an extended partition; There is a logical partition under it. In fact, this partition is equivalent to a container; Her subordinates are hda5, HDA6, hda7, hda8 and hda9;

We have also noticed one point. Why is there no hda4? Why is hda4 not included in the extended partition? A disk can have up to four primary partitions; Hda1-4 are all primary partitions; Hda4 cannot be included in the extended partition. In addition, the extended partition is also the primary partition; In this case, there is no hda4 partition. Of course, we can partition one of themset upMain partition, but I didn’t do that when I was partitioning;

Let’s take a closer look. Let’s see if there is still space on this disk? Hda1 + hda2 + hda3 = the actual volume of the partition, so we can calculate hda1 + hda2 + hda3 = 6144831 + 16386300 + 39728745 = 62259876 (b), which is converted into m units, and the decimal point is moved forward by three digits. Therefore, the approximate occupied volume of the partition is 62259.876 (m), in fact, the most accurate calculation is 62259876 / 1024 = 60800.67 (m); The disk size is 80.0 GB (80026361856byte). In fact, the actual size is 78150.744 (m); Through a series of calculations, we can conclude that the hard disk still has space to use at present; There is about 18G of unpartitioned space;

Fdisk -l can list the number of all disks in the machine and the partition of all disks; For example:

[[email protected] beinan]# fdisk -l

Disk /dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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 7751 39728745 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

Disk /dev/sda: 60.0 GB, 60011642880 bytes

64 heads, 32 sectors/track, 57231 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System

/dev/sda1 1 57231 58604528 83 Linux

From the above, we can know that this machine has two hard disks. We can also specify fdisk – L to view the partition of one of the hard disks;

[[email protected] beinan]# fdisk -l /dev/sda

Disk /dev/sda: 60.0 GB, 60011642880 bytes

64 heads, 32 sectors/track, 57231 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System

/dev/sda1 1 57231 58604528 83 Linux

As can be seen from the above situation, there is only one partition in the disk / dev / SDA; The usage is almost 100%;

We can also check the of / dev / HDA

[[email protected] beinan]# fdisk -l /dev/hda

Try it yourself?

3、 Cfdisk comes from util linux software package;

Cfdisk is also a good partitioning tool; In some distributions, this tool has been removed from the util Linux package; Cfdisk is simple and easy to use; Similar to fdisk in DOS; In this title, we will only explain how to view the disk partition status and the files used in the machinesystemEtc;

View the usage of disk partition cfdisk – PS disk device name;

such as

[[email protected] beinan]cfdisk -Ps

[[email protected] beinan]cfdisk -Ps /dev/hda

[[email protected] beinan]cfdisk -Ps

Partition Table for /dev/hda

First Last

# Type Sector Sector Offset Length Filesystem Type (ID) Flag

— ——- ———– ———– —— ———– ——————– —-

1 Primary 0 23438834 63 23438835 Linux (83) Boot

2 Primary 23438835 156296384 0 132857550 Extended (05) None

5 Logical 23438835 155268224 63 131829390 Linux (83) None

6 Logical 155268225 156296384 63 1028160 Linux swap (82) None

We only use the parameter – PS to list the partition of the disk; At present, cfdisk exists in mainstream distributions such as Slackware Debian Mandrake, and fedora 4.0 eliminates this gadget; It’s a pity; This is me in Slackwareoperationof

If you dooperation, it is more intuitive;

[ [email protected] Beinan]cfdisk disk disk device name

give an example:

[[email protected] beinan]cfdisk /dev/hda

What you see is the following pattern:

cfdisk 2.12a

Disk Drive: /dev/hda

Size: 80026361856 bytes, 80.0 GB

Heads: 255 Sectors per Track: 63 Cylinders: 9729

Name Flags Part Type FS Type [Label] Size (MB)

——————————————————————————————-

hda1 Boot Primary Linux ReiserFS 12000.69

hda5 Logical Linux ReiserFS 67496.65

hda6 Logical Linux swap 526.42

[Bootable] [ Delete ] [ Help ] [Maximize] [ Print ] [ Quit ]

[ Type ] [ Units ] [ Write ]

Toggle bootable flag of the current partition

You have entered the cfdiskoperationInterface; Move the pointer to [quit] with the keyboard to exit;

4、 Parted is a partition tool with good functions; There is a tape in Fedora 4.0, which can be used by yourselfinstallOn; In this topic, we only talk about how to view the partition of the disk;

callmethodSimple. Parted is opened by default, and the device is / dev / HDA. You can also specify it yourself; For example, parted / dev / HDA or / dev / SDA; ExitedmethodIt’s quit

[[email protected] beinan]# parted

Use / dev / HDA

(parted) p

/Disk geometry of dev / HDA: 0.000-76319.085 megabytes

Disk label type: MSDOS

Minor start and end point type filesystemsign

1 0.031 6000.842 NTFS startup of primary partition

2 6000.842 22003.088 main partition FAT32 LBA

3 22003.088 60800.690 expansion partition

5 22003.119 30004.211 logical partition ReiserFS

6 30004.242 40005.615 logical partition ReiserFS

7 40005.646 40774.350 logical partition Linux swap

8 40774.381 52219.094 logical partition ext3

9 52219.125 60800.690 logical partition ReiserFS

We’re at the partyoperationOn the surface, use p to list the partition of the current disk. If you want to view other disks, you can use the select function, such as select / dev / SDA;

5、 Qtparted, the software related to parted and qtparted can also view the structure of the disk and the files usedsystem, is graphical;

[[email protected] ~]# qtparted

Graphical view, clear at a glance;

6、 Sfdisk is also a partition tool with many functions; Here we only talk about the functions of the column disk partition;

[[email protected] beinan]# sfdisk -l

See for yourself;

Sfdisk has several useful functions; Interested brothers might as well have a look;

7、 PartX also briefly said that somesystemWith this tool, the function is also simple, which is not worth mentioning compared with fdisk, parted and cfdisk; No need;

Usage: partX device name

[[email protected] beinan]# partx /dev/hda

# 1: 63- 12289724 ( 12289662 sectors, 6292 MB)

# 2: 12289725- 45062324 ( 32772600 sectors, 16779 MB)

# 3: 45062325-124519814 ( 79457490 sectors, 40682 MB)

# 4: 0- -1 ( 0 sectors, 0 MB)

# 5: 45062388- 61448624 ( 16386237 sectors, 8389 MB)

# 6: 61448688- 81931499 ( 20482812 sectors, 10487 MB)

# 7: 81931563- 83505869 ( 1574307 sectors, 806 MB)

# 8: 83505933-106944704 ( 23438772 sectors, 12000 MB)

# 9: 106944768-124519814 ( 17575047 sectors, 8998 MB)

8、 Check all disks and partitions in the current machine:

[[email protected] ~]$ cat /proc/partitions

major minor #blocks name

3 0 78150744 hda

3 1 6144831 hda1

3 2 16386300 hda2

3 5 8193118 hda5

3 6 10241406 hda6

3 7 787153 hda7

3 8 11719386 hda8

3 9 8787523 hda9

8 0 58605120 sda

8 1 58604528 sda1