检查Linux磁盘分区和Linux使用情况的好工具
您是系统管理员吗,那么您应该了解这些工具来管理磁盘空间。本文介绍了有关如何在Linux中检查Linux磁盘分区和使用情况的信息。
软盘
Fdisk是基于文本的实用程序。通过使用fdisk,您可以创建一个全新的分区,删除当前分区或交换现有分区。
要获取有关fdisk的更多信息,请使用以下命令–
$ fdisk
样本应该是这样的–
Usage: fdisk [options] change partition table fdisk [options] -l [] list partition table(s) Display or manipulate a disk partition table. Options: -b, --sector-size physical and logical sector size -B, --protect-boot don't erase bootbits when create a new label -c, --compatibility[=] mode is 'dos' or 'nondos' (default) -L, --color[=] colorize output (auto, always or colors are enabled by default -l, --list display partitions end exit -o, --output output columns -t, --type recognize specified partition table type only -u, --units[=] display units: 'cylinders' or 'sectors' (default) -s, --getsz display device size in 512-byte sectors [DEPRECATED] --bytes print SIZE in bytes rather than in human readable format -C, --cylinders specify the number of cylinders -H, --heads specify the number of heads -S, --sectors specify the number of sectors per track -h, --help display this help and exit -V, --version output version information and exit Available columns (for -o): gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S Start-C/H/S bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize sgi: Device Start End Sectors Cylinders Size Type Id Attrs sun: Device Start End Sectors Cylinders Size Type Id Flags ..........................................................................................
要获取设备列表,请使用以下命令–
$ sudo fdisk -l
样本输出应如下所示–
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes
磁盘
sfdisk是基于脚本的工具,用于显示或操作磁盘分区表。
要获取有关sfdisk的更多信息,请使用以下命令–
$ man sfdisk
样本输出应如下所示–
SFDISK(8) System Administration SFDISK(8) NAME sfdisk - display or manipulate a disk partition table SYNOPSIS sfdisk [options] device [-N partition-number] sfdisk [options] command DESCRIPTION sfdisk is a script-oriented tool for partitioning any block device. Since version 2.26 sfdisk supports MBR (DOS), GPT, SUN and SGI disk labels, but no longer provides any tionality for CHS (Cylinder-Head-Sector) addressing. CHS has never been important for Linux, and this addressing concept does not make any sense for new devices. sfdisk (since version 2.26) aligns the start and end of partitions to block-device I/O limits when relative sizes are specified, or when the default values are used. sfdisk does not create the standard system partitions for SGI and SUN disk labels like fdisk(8) does. It necessary to explicitly create all partitions including whole-disk system partitions. ........................................................................................
要获取设备列表,请使用以下命令–
$ sfdisk -l
样本输出应如下所示–
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes
lsblk
lsblk提供有关所有或特定块设备的信息。要获取有关lsblk的更多信息,请使用以下命令–
$ man lsblk
样本输出应如下所示–
LSBLK(8) System Administration LSBLK(8) NAME lsblk - list block devices SYNOPSIS lsblk [options] [device...] DESCRIPTION lsblk lists information about all available or the specified block devices. The lsblk command reads the sysfs filesystem and udev db to gather information. The command prints all block devices (except RAM disks) in a tree-like format by default. Use lsblk --help to get a list of all available columns. The default output, as well as the default output from options like --fs and --topology, is subject to change. So whenever pos‐sible, you should avoid using default outputs in your scripts. Always explicitly define expected columns by using --output col‐umns-list in environments where a stable output is required. Note that lsblk might be executed in time when udev does not have all information about recently added or modified devices yet. In this case it is recommended to use udevadm settle before lsblk to synchronize with udev. .................................................................................................
要获取设备列表,请使用以下命令–
$ lsblk
样本输出应如下所示–
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465.8G 0 disk ├─sda1 8:1 0 462.3G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 3.4G 0 part [SWAP] sr0 11:0 1 1024M 0 rom
lsscsi
它提供有关当前连接到系统的SCSI设备(或主机)列表的信息。要获取有关lsscsi的更多信息,请使用以下命令–
$ man lsscsi
样本输出应如下所示–
NAME lsscsi - list SCSI devices (or hosts) and their attributes SYNOPSIS lsscsi [--classic] [--device] [--generic] [--help] [--hosts] [--kname] [--list] [--lunhex] [--long] [-- protection] [--protmode] [--scsi_id] [--size] [--sysfsroot=PATH] [--transport] [--verbose] [--version] [--wwn] [H:C:T:L] DESCRIPTION Uses information in sysfs (Linux kernel series 2.6 and later) to list SCSI devices (or hosts) currently attached to the system.Options can be used to control the amount and form of information provided for each device. If a H:C:T:L argument is given then it acts as a filter and only devices that match it are listed. The colons don't have to be present, and '-', '*', '?' or missing arguments at the end are interpreted as wildcards. The default is '*:*:*:*' which means to match everything. Any filter string using '*' of '?' should be surrounded by single or double quotes to stop shell expansions. If '-' is used as a wildcard then the whole filter argument should be prefixed by '-- ' to tell this utility there are no more options on the command line to be interpreted. A leading '[' and trailing ']' are permitted (e.g. '[1:0:0]' matches all LUNs on 1:0:0). May also be used to filter --hosts in which case only the H is active and may be either a number or in the form "host" where is a host number. ............................................................................................
要获取当前连接的SCSI设备(或主机)的列表,请使用以下命令-
$ lsscsi
样本输出应如下所示–
[0:0:0:0] disk ATA WDC WD5000LPVX-7 1A01 /dev/sda [1:0:0:0] cd/dvd TSSTcorp DVD+-RW SU-208FB D200 /dev/sr0
在本文中,我们学习了一些非常有用的工具-“检查Linux磁盘分区和Linux中的使用情况”。在我们的下一篇文章中,我们将提出更多基于Linux的技巧。继续阅读!