Свободное место на диске в Linux

Contents
Введение
Examine disk space usage
Examine disk space usage by file and directory
Examine the desired directory
Retain log entries
SMART errors
Похожие статьи

It is often needed to know how much free space you have and which files are eating most space.

Examine disk space usage

To examine your system’s disk space usage, run the following command:

df -h

The output will resemble the following example:

Filesystem Size Used Avail Use% Mounted on devtmpfs 903M 0 903M 0% /dev tmpfs 919M 0 919M 0% /dev/shm tmpfs 919M 44M 876M 5% /run tmpfs 919M 0 919M 0% /sys/fs/cgroup /dev/mapper/centos-root 14G 11G 3.0G 79% / /dev/sda1 1014M 330M 685M 33% /boot tmpfs 184M 0 184M 0% /run/user/1000

This output indicates that the system’s main storage device (/dev/mapper/centos-root) in the root (/) directory uses 79% of its available disk space and contains 3 GB of free space.

Examine disk space usage by file and directory

If your system currently uses too much disk space, perform the following steps to identify files to delete:

To determine which files and directories consume most of your hard drive space, run the du command.

du -h

The output will resemble the following example:

132K ./home/andrei/.config 0 ./home/andrei/Public 0 ./home/andrei/Music 0 ./home/andrei/Videos 30M ./home/andrei/.mozilla/firefox 16K ./home/tester 3.3G ./home 0 ./media 0 ./mnt 7.9M ./opt/VBoxGuestAdditions-6.1.26/src 19M ./opt/VBoxGuestAdditions-6.1.26 19M ./opt 0 ./srv 0 ./var/account 2.5G ./var

Note: We recommend that you only run this command in off-peak hours to prevent additional load on your server. The numbers in the left column represent the sizes of the files and directories that the working directory contains, in human-readable format. In this example, the /home directory, which generally contains the system’s account data, uses the most disk space (113 GB). Because in most cases you cannot delete your users’ data, examine the second largest directory (the /var directory) for disk usage data.

Banner Image

Examine the desired directory

To examine the desired directory, run the following command:

du -sh /var/*

The output will resemble the following example:

0 /var/account 0 /var/adm 548M /var/backups 706M /var/cache 0 /var/crash 8.0K /var/db 0 /var/empty 0 /var/games 0 /var/gopher 0 /var/kerberos 1.2G /var/lib 0 /var/local 0 /var/lock 1.4G /var/log 0 /var/mail 0 /var/nis 0 /var/opt 0 /var/preserve 0 /var/run 40K /var/spool 36K /var/tmp 0 /var/yp

This output indicates that the /var/log/ directory uses the most disk space.

Repeat this process until you locate files that you wish to remove.

To delete the desired files, run the following command, where filename represents the file to remove:

0 /var/account 0 /var/adm 548M /var/backups 706M /var/cache 0 /var/crash 8.0K /var/db 0 /var/empty 0 /var/games 0 /var/gopher 0 /var/kerberos 1.2G /var/lib 0 /var/local 0 /var/lock 66M /var/log 0 /var/mail 0 /var/nis 0 /var/opt 0 /var/preserve 364K /var/privx 0 /var/run 40K /var/spool 36K /var/tmp 0 /var/yp

rm -f filename

Warning:

Exercise caution when you run the rm utility. You cannot recover files or directories that you delete.

Retain log entries

Log files often use a large amount of disk space. To retain the system’s most recent log file entries when you remove excess log files, perform the following steps: If you have not already located the specific files to remove from this directory, run the du command. Examine the command’s output to determine the files to delete. For each file, run the following commands, where filename represents the file’s name.

tail -5000 filename > filename.new mv filename.new filename sync

To release the file lock, restart the service that created the file.

SMART errors

Warning: Self-Monitoring, Analysis and Reporting Technology (SMART) errors may indicate hard disk failures or other problems. Only disable SMART errors if you understand these risks.

To disable SMART errors, run the following commands:

touch /var/cpanel/disablesmartcheck
/scripts/upcp

Related Articles
Linux
Debian
Ubuntu
CentOS
Rocky
Bash
Network Configuration
Files
Examine Free Disk Space
Combine .pdf Files
diff: Compare Files
find: Search for Files
kill: Finish Process
rename
make
signal: System Signals
env: Environmental Variables
localectl: langugae
systemctl: List of Active Services
Firewall
SCP: File Exchange
SSH: Remote Access
cron: Tasks in Timetable
sudo
Monitoring
C
C++

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedbak and Questions in Telegram

@aofeedchat