Daily
find . -type f -exec du -h {} + | sort -rh | head -n 10
du -ah / | sort -rh | head -n 10
Explanation:
du -ah /: This command starts at the root directory / and prints disk usage for all files and directories in human-readable format (-h) and includes all files (-a).
sort -rh: This sorts the output of the du command in reverse (-r) and by human-readable numbers (-h), so the largest sizes come first.
head -n 10: This selects the top 10 lines from the sorted output.
du -sh /* | sort -rh | head -n 10
Explanation:
du -sh /*: This command will give you a summary (-s) of the disk usage for directories in the root (/) directory in human-readable format (-h), without including individual files.
current folder: du -ah . | sort -rh | head -n 10
siton-2009
只要你不需要日志进行任何调试,可以删除/var/log/journal/* 内的所有内容,但不要删除/var/log/journal目录本身
sudo journalctl --vacuum-size=50M
sudo journalctl --vacuum-time=1weeks
Restart the journald service to apply changes:
sudo systemctl restart systemd-journald
To set up a weekly cleanup of the /www/backup/panel folder, you can create a cron job that runs a script to delete old files in the folder. Here’s how you can do it:
- Create a Cleanup Script
First, create a script that will delete the files in the /www/backup/panel directory.
Open a new file for your script:
sudo nano /usr/local/bin/cleanup_panel_backup.sh
Add the following content to the script:
!/bin/bash
// Script to clean up the /www/backup/panel folder
// Delete all files in the /www/backup/panel directory
rm -rf /www/backup/panel/*
Save the file and exit the editor (Ctrl + X, then Y, then Enter).
Make the script executable:
sudo chmod +x /usr/local/bin/cleanup_panel_backup.sh
- Create a Cron Job for Weekly Cleanup
Next, create a cron job that runs this script weekly.
Open the crontab file for editing:
sudo crontab -e
Add the following line to schedule the script to run every week (e.g., every Sunday at 2:00 AM):
0 2 0 /usr/local/bin/cleanup_panel_backup.sh
Here's how the cron schedule works:
0 2 0: This means "At 02:00 AM, on Sunday, every week."
/usr/local/bin/cleanup_panel_backup.sh: This is the path to the script you created.
Save and exit the crontab editor (Ctrl + X, then Y, then Enter).
- Verify the Cron Job
To ensure the cron job is set up correctly, you can list all cron jobs:
sudo crontab -l
/var
/var/cache/apt/archives
这里保存的是已经下载过的 .deb 包,安装后不会自动删除。
sudo apt clean # 删除所有缓存包
sudo apt autoclean # 删除过期的缓存包
/var/lib/apt/lists
保存软件源索引,apt 会在下次 apt update 时重新生成。
sudo rm -rf /var/lib/apt/lists/*
sudo apt update # 清空后重新生成索引
一键执行安全的组合清理:
sudo apt clean
sudo apt autoclean
sudo apt autoremove -y
sudo journalctl --vacuum-time=7d
sudo du -sh /var/*
Swapfile
swapfile 是 Linux 系统的交换空间(Swap Space),它的作用就像“虚拟内存”。
当系统物理内存(RAM)不够用时,操作系统会把暂时不用的数据从内存转移到 swapfile,以释放内存给活跃的程序。
这可以防止系统因内存耗尽而崩溃。
如何调整大小
sudo swapoff /swapfile
sudo rm /swapfile
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
总结
你服务器的类型 建议操作
小内存 VPS(1~2GB) 保留 1~2GB swapfile
中内存服务器(4~8GB) 可调小为 512MB~1GB
大内存物理机(>16GB) 可关闭 swap,提高 SSD 寿命