![如何释放 /dev/sda9 中的空间](https://linux22.com/image/914504/%E5%A6%82%E4%BD%95%E9%87%8A%E6%94%BE%20%2Fdev%2Fsda9%20%E4%B8%AD%E7%9A%84%E7%A9%BA%E9%97%B4.png)
它说bash: cannot create temp file for here-document: No space left on device
空间分布如下:
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 787M 9.8M 777M 2% /run
/dev/sda9 19G 18G 8.0K 100% /
tmpfs 3.9G 172K 3.9G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 787M 36K 787M 1% /run/user/1000
如何解决?
答案1
这是我运行以释放根分区空间的脚本
function myclean {
## Show free space
df -Th | grep -v fs
# Will need English output for processing
LANG=en_GB.UTF-8
## Clean apt cache
apt-get update
apt-get -f install
apt-get -y autoremove
apt-get clean
## Remove old versions of snap packages
snap list --all | while read snapname ver rev trk pub notes; do
if [[ $notes = *disabled* ]]; then
snap remove "$snapname" --revision="$rev"
fi
done
## Set snap versions retain settings
if [[ $(snap get system refresh.retain) -ne 2 ]]; then snap set system refresh.retain=2; fi
rm -f /var/lib/snapd/cache/*
## Remove old versions of Linux Kernel
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs apt-get -y purge
## Rotate and delete old logs
/etc/cron.daily/logrotate
find /var/log -type f -iname *.gz -delete
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s
## Show free space
df -Th | grep -v fs
}