Home Common Problem How to check disk space size in linux

How to check disk space size in linux

Jun 30, 2023 pm 05:24 PM
linux

linux查看磁盘空间大小的方法:1、通过df命令检查;2、通过fdisk命令检查;3、通过parted命令检查;4、通过du命令检查;5、通过lsblk命令检查;6、通过blockdev命令检查;7、通过lshw命令检查;8、通过查看系统日志来检查;9、通过lsscsi来检查;10、通过sfdisk来检查。

How to check disk space size in linux

作为一个Linux管理员,管理 Linux 服务器上的磁盘空间是一项重要任务。例如,安装包管理器应用程序会提示需要多少磁盘空间,这个时候应该知道系统有多少可用空间,这样才能够使这个应用程序能够正常的安装并且运行。下面就来看一下如何使用不同的命令和方法来检查Linux中的磁盘空间。这些命令和方法中的大多数应该在大多数Linux发行版上可用。通过这些命令还可以创建脚本来监视磁盘大小使用情况并创建警报或发送邮件(这需要邮件服务器)才行。

1,通过df命令检查

df 是检查Linux安装程序上可用分区空间的最常用的命令之一。可以使用“df -TH”以直观易读的格式打印分区类型和分区大小。此命令将显示每个部分的总可用空间、已用空间和可用空间。

[sharplee@sharplee creatfile]# df -TH
Copy after login

How to check disk space size in linux

还可以使用其他参数(df -THi)来打印每个分区的可用、已用和未使用的inode计数。

How to check disk space size in linux

2,通过fdisk命令检查

fdisk是另一个非常方便的系统管理员实用程序。fdisk是一个用户交互式程序,主要用于创建和操作分区表,例如创建,删除,修改分区。但是,也可以使用此实用程序列出连接到Linux系统的可用磁盘以及相应的磁盘大小。

[sharplee@sharplee creatfile]# fdisk -l
Copy after login

How to check disk space size in linux

通过上面可以看出/dev/sda磁盘的大小是21.5G。输出还显示了有关此磁盘的更多详细信息,其中它包含两个分区 /dev/sda1 和 /dev/sda2。"fdisk -l"的输出可以看出输出很多内容并且很长,如果只想检查磁盘空间,可以使用这个命令:

[sharplee@sharplee creatfile]# fdisk -l | awk '$1=="Disk" && $2 ~ 
/^\/dev\/.*/ {print $2 $3 $4}'
Copy after login

How to check disk space size in linux

3,通过parted命令检查

parted 是 fdisk 的另一种替代方案,也用于操作磁盘分区。它对于为新操作系统创建空间、重新组织磁盘使用情况以及将数据复制到新硬盘非常有用。与 fdisk 类似,可以使用 parted -l 列出所有可用磁盘及其各自的大小:

[root@sharplee creatfile]# parted -l
Copy after login

How to check disk space size in linux

和fdisk命令一样,parted命令展示的内容太多,也可以使用以下命令查看具体的磁盘空间。

[root@sharplee creatfile]# parted -l | awk '$1=="Disk" && $2 ~ 
/^\/dev\/.*/ {print $2 $3 $4}'
Copy after login

How to check disk space size in linux

4,通过du命令检查

du是另一个很棒的实用程序,用于在Linux中以递归方式检查文件大小。它还可以以递归方式汇总目录的文件集的磁盘使用情况。du 是一个非常通用的工具,支持多个参数。

[root@sharplee creatfile]# du -h /boot/*
Copy after login

How to check disk space size in linux

上图是通过递归来打印/boot/分区下的文件大小。下图是打印总的分区的大小。

[root@sharplee creatfile]# du -sch /boot/*
Copy after login

How to check disk space size in linux

下图是展示该分区下大于20M的文件的列表。

[root@sharplee creatfile]# du -ach -t 20M /boot/* | sort -hr
Copy after login

How to check disk space size in linux

5,通过lsblk命令检查

lsblk列出了有关所有可用或指定块设备的信息。lsblk 命令读取 sysfs 文件系统和udevdb以收集信息。如果udevdb不可用,或者lsblk在没有udevdb支持的情况下编译,则它会尝试从块设备读取LABEL、UUID和文件系统类型。

[root@sharplee creatfile]#lsblk
Copy after login

How to check disk space size in linux

6,通过blockdev命令检查

可以使用blockdev命令为指定设备打印报告。也可以给多个设备打印。如果未给出任何设备,则会显示出现在 /proc/分区中的所有设备。请注意,分区 StartSec 位于 512 字节扇区中。

[root@sharplee creatfile]# blockdev --report
Copy after login

How to check disk space size in linux

7,通过lshw命令检查

lshw是一个小工具,用于提取有关计算机硬件配置的详细信息。它可以报告支持 DMI 的 x86 或 IA-64 系统以及某些 PowerPC 机器上的确切内存配置、固件版本、主板配置、CPU 版本和速度、缓存配置、总线速度等。

[root@sharplee creatfile]# lshw -c disk | grep -E "logical name|size:"
Copy after login

How to check disk space size in linux

8,通过查看系统日志来检查

使用系统日志来查看,例如使用 dmesg 或 journalctl -b 的引导日志,并尝试搜索相应的磁盘以获取更多信息。

[root@sharplee creatfile]# dmesg | grep sda
Copy after login

How to check disk space size in linux

9,通过lsscsi来检查

sscsi使用sysfs(Linux 内核系列 2.6 及更高版本)中的信息来列出当前连接到系统的SCSI设备(或主机)。许多非SCSI存储设备(但不是全部)在Linux中使用SCSI子系统。在lsscsi版本中,0.30版支持已添加到列出NVMe设备。

[root@sharplee creatfile]# lsscsi --size
Copy after login

How to check disk space size in linux

10,通过sfdisk来检查

sfdisk再次是fdisk和parted的替代品。fdisk和sfdisk之间的主要区别之一是 sfdisk读取和写入分区表,但不像 fdisk或cfdisk那样是交互式的(它从文件或stdin读取输入)。它通常用于从脚本中对驱动器进行分区或用于分区表备份和恢复。

[root@sharplee creatfile]# sfdisk -s
Copy after login

How to check disk space size in linux

The above is the detailed content of How to check disk space size in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Difference between centos and ubuntu Difference between centos and ubuntu Apr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

Detailed explanation of docker principle Detailed explanation of docker principle Apr 14, 2025 pm 11:57 PM

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.