GXCOM 服务器 Linux 服务器磁盘空间已满:查找大文件、清理日志并回收存储空间
Cherry Servers 独立服务器、VPS、GPU 服务器和裸机基础设施

Linux 服务器磁盘空间已满:查找大文件、清理日志并回收存储空间

A Linux server disk full error can interrupt websites, databases, backups, and application deployments. The message “No space left on device” often appears when a filesystem reaches capacity, but it can also indicate exhausted inodes rather than insufficient storage bytes.

Before deleting anything, identify the affected filesystem and understand what consumes its resources. This guide explains safe diagnostic commands, log cleanup, deleted-file recovery, and when upgrading VPS or cloud storage makes sense.

Linux 服务器磁盘空间已满的故障排除:介绍 df 和 du 命令、大文件检测、日志清理、inode 使用情况以及 VPS 存储恢复

1. Check Linux Disk Usage with df

Start by checking mounted filesystem capacity:

df -hT

The output shows filesystem type, total capacity, available space, utilization, and mount points. Focus on the filesystem reporting 100% usage rather than assuming the root partition is responsible.

Next, check inode availability:

df -i

Inodes track filesystem objects. Millions of small files can exhaust available inodes even when storage capacity remains. If inode usage is full, deleting a few large files may not resolve the problem.

Record the affected mount point before continuing.

2. Find Large Directories with du

该 du command helps locate directories consuming storage. For the root filesystem, run:

sudo du -xhd1 / 2>/dev/null | sort -h

该 -x option prevents traversal into other mounted filesystems. Inspect unusually large directories individually, such as /var, /home, or application storage paths.

例如:

sudo du -xhd1 /var 2>/dev/null | sort -h

Do not assume a large directory is disposable. Database files, virtual machine images, and application uploads may contain essential production data.

3. Find Large Files Safely

To locate files larger than 500 MB on the root filesystem, use:

sudo find / -xdev -type f -size +500M \
-printf '%s %p\n' 2>/dev/null | sort -nr | head -20

The first column reports file size in bytes. Review the resulting paths before making changes.

Common storage consumers include archived logs, abandoned backups, container images, database exports, and temporary application files.

Never automatically delete files returned by a size-based search. A large file may be necessary for a running service.

4. Clean Linux Logs Without Breaking Services

System logs can grow rapidly when applications repeatedly report errors. Inspect journal usage:

sudo journalctl --disk-usage

If the journal is unusually large, consider a controlled cleanup:

UltaHost 的 VPS、独立服务器和云托管解决方案
sudo journalctl --rotate
sudo journalctl --vacuum-size=500M

The first command rotates active journal files. The second removes eligible archived journal files according to the specified size target. It does not guarantee that total journal usage immediately falls below 500 MB.

For traditional logs, inspect /var/log and confirm whether logrotate is configured correctly.

Avoid deleting active log files blindly. Fix the underlying error generating excessive logs, or the disk may fill again.

5. Fix Deleted Files Still Using Disk Space

有时 df reports a full filesystem while du cannot account for the usage. One possible cause is a deleted file still held open by a running process.

Check with:

sudo lsof +L1

This lists open files with a link count below one, including deleted files still occupying storage.

Identify the responsible service before taking action. A controlled service restart may release the file descriptor, but restarting databases or production applications can interrupt users.

Investigate other explanations for df 以及 du differences, including filesystem metadata, reserved blocks, and inaccessible directories.

6. Investigate Docker and Application Storage

Container images, build caches, volumes, and logs can consume substantial disk space.

For Docker installations, inspect usage:

docker system df

Review unused resources before removing them. Avoid indiscriminate pruning, especially commands that remove volumes, because persistent application data may be lost.

Also inspect application uploads, package caches, database exports, and scheduled backup directories.

If backups are contributing to capacity problems, our VPS 快照与备份恢复指南 explains how to plan recovery storage without relying on a single local copy.

7. Recover Space and Verify Services

After identifying genuinely unnecessary files, remove or archive them through the appropriate application or system maintenance procedure.

Then rerun:

df -hT
df -i

Confirm that free capacity and inode availability have improved. Check web server, database, and application logs for continued errors.

When a full disk causes service failures, restoring free space alone may not repair corrupted transactions or interrupted background tasks. Validate application health and backups before declaring recovery complete.

8. Prevent Future Disk Full Incidents

Set storage alerts before utilization reaches critical levels. Monitor capacity growth, inode consumption, log retention, and backup schedules.

Review recurring growth patterns and establish realistic headroom for database writes, temporary files, package updates, and application deployments.

Storage performance matters as well as capacity. Our NVMe VPS 与 SSD 性能对比指南 explains why disk technology, latency, and workload characteristics deserve separate evaluation.

9. When Should You Upgrade VPS Storage?

Consider upgrading when legitimate application data continues growing despite sensible retention policies, or when available storage no longer supports safe operations.

Check whether your hosting plan supports disk expansion, whether filesystem resizing is required, and whether the change involves downtime.

For general purchasing decisions, read our 最佳VPS服务商对比.

Evoxt and Hostwinds are relevant for Linux VPS buyers comparing configurations and management options. Contabo VPS/VDS may interest users evaluating storage capacity against overall resource requirements.

探索 Evoxt VPS plans and verify current disk capacity, pricing, and expansion policies before purchasing.

10. Cloud Servers vs Dedicated Storage

卡马特拉 offers configurable cloud server resources for organizations that need to evaluate capacity and infrastructure flexibility.

Cloudways 托管云主机——高性能、托管安全、自动备份和轻松扩展

Cherry 服务器 provides bare-metal options for workloads requiring greater physical hardware control, such as large databases or storage-intensive applications.

Dedicated hardware does not automatically eliminate capacity planning, filesystem limits, or backup requirements.

我们的 专用服务器与云服务器的对比 explains the operational tradeoffs between these deployment models.

常见问题解答

Why Is Linux Disk Full After Deleting Files?

Deleted files may remain open in running processes. Check lsof +L1 and investigate filesystem accounting before restarting services.

Can Linux Run Out of Inodes?

Yes. Large numbers of small files can exhaust inodes even when disk capacity remains available. Check using df -i.

Should I Delete Everything in /var/log?

No. Logs are important for troubleshooting and security. Use controlled rotation and retention policies instead of indiscriminate deletion.

最终裁决

When a Linux server disk is full, start with df, locate large directories with du, investigate files with 查找, and check logs and open deleted files.

Recover space carefully, verify application health, and establish monitoring. If legitimate storage demand exceeds your plan, compare VPS, cloud, and dedicated infrastructure based on actual capacity, performance, and recovery requirements.

For broader infrastructure selection, consult our 裸机服务器对比 在决定采用实体硬件之前。.

© GXCOM.NET。本网站上的所有内容均代表我们团队的独立研究、编辑分析及原创见解。任何转载、引用或再发布均须注明原始来源,并附上原文链接。.https://www.gxcom.net/zh/linux-server-disk-full/
Hostwinds 云服务器、VPS 托管和独立服务器解决方案 DediXLAB Windows VPS、Linux VPS、独立服务器和混合服务器
下一篇
Linux 服务器磁盘空间已满的故障排除:介绍 df 和 du 命令、大文件检测、日志清理、inode 使用情况以及 VPS 存储恢复

没有更多帖子了

订阅
通知
访客
0 评论
最旧的
最新 得票最多
返回顶部
0
很想听听大家的看法,请留言。.x