mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
translated
This commit is contained in:
parent
88bb139bf4
commit
df5422b944
@ -1,106 +0,0 @@
|
||||
[#]: subject: "How to Clean Up Snap Versions to Free Up Disk Space"
|
||||
[#]: via: "https://www.debugpoint.com/clean-up-snap/"
|
||||
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
How to Clean Up Snap Versions to Free Up Disk Space
|
||||
======
|
||||
|
||||
**This quick guide with a script helps to clean up old snap versions and free some disk space in your Ubuntu systems.**
|
||||
|
||||
I was running out of disk space in my test system with Ubuntu. So I was investigating via GNOME’s Disk Usage Analyser to find out which package is consuming the precious SSD space. Apart from the usual cache and home directory – to my surprise, I found that Snap and Flatpak consume a considerable amount of storage space.
|
||||
|
||||
![Snap size - before cleanup][1]
|
||||
|
||||
Although, I always maintain a rule – not to use Snap or Flatpak unless necessary. This is mainly because of their installation size and other issues. I prefer vanilla deb and rpm packages. Over the years, I have installed and removed a certain amount of Snap packages in this test system.
|
||||
|
||||
The problem arises after uninstallation; Snap keeps some residue files in the system, unknown to the general users.
|
||||
|
||||
So I opened the Snap folder `/var/lib/snapd/snaps` and discovered that Snap is keeping track of older versions of previously installed/uninstalled packages.
|
||||
|
||||
For example, in the below image, you can see GNOME 3.28, 3.34, and Wine – all of these are removed long back. But they are still there. It’s happening because of the Snap design, which keeps versions of uninstalled packages after a proper uninstallation.
|
||||
|
||||
![Files under snaps directory][2]
|
||||
|
||||
Alternatively, you can get the same in the terminal using:
|
||||
|
||||
```
|
||||
snap list --all
|
||||
```
|
||||
|
||||
![snap list all][3]
|
||||
|
||||
The default value is 3 for several revisions for retention. That means Snap keeps three older versions of each package, including the active version. This is okay if you do not have constraints on your disk space.
|
||||
|
||||
But for servers and other use cases, this can easily run into cost issues, consuming your disk space.
|
||||
|
||||
However, you can easily modify the count using the following command. The value can be between 2 to 20.
|
||||
|
||||
```
|
||||
sudo snap set system refresh.retain=2
|
||||
```
|
||||
|
||||
### Clean Up Snap Versions
|
||||
|
||||
In a post in SuperUser, Popey, the ex-Engineering Manager at Canonical, [provided a simple script][4] that can clean up old versions of Snaps and keep the latest one.
|
||||
|
||||
Here’s the script we will use to clean the Snap up.
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
#Removes old revisions of snaps
|
||||
#CLOSE ALL SNAPS BEFORE RUNNING THIS
|
||||
set -eu
|
||||
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
|
||||
while read snapname revision; do
|
||||
snap remove "$snapname" --revision="$revision"
|
||||
done
|
||||
```
|
||||
|
||||
Save the above script as .sh in a directory (for example`clean_snap.sh`), give it executable permission and run.
|
||||
|
||||
```
|
||||
chmod +x clean_snap.sh
|
||||
```
|
||||
|
||||
When I ran the script, it reduced a lot of disk space. The script would also show the name of the package being removed.
|
||||
|
||||
![Executing the script][5]
|
||||
|
||||
![Snaps size after cleanup][6]
|
||||
|
||||
### Closing Notes
|
||||
|
||||
There are always debates on how efficient Snap’s design is. Many say it is broken by design, bloated, and heavy on systems. Some part of that argument is true, I would not deny it. The whole concept of sandboxing applications is great if implemented and enhanced properly. I believe, Flatpak does a better job compared to Snap.
|
||||
|
||||
That said, I hope this helps you clean up some disk space. Although it is tested in Ubuntu, it should work in all Linux distribution that supports Snap.
|
||||
|
||||
Also, check out our guide on [how to clean up Ubuntu][7] with additional steps.
|
||||
|
||||
Finally, if you are looking to clean up **Flatpak** apps, refer [this guide][8].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/clean-up-snap/
|
||||
|
||||
作者:[Arindam][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.debugpoint.com/author/admin1/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.debugpoint.com/wp-content/uploads/2021/03/Snap-size-before-cleanup.jpg
|
||||
[2]: https://www.debugpoint.com/wp-content/uploads/2021/03/Files-under-snaps-directory.jpg
|
||||
[3]: https://www.debugpoint.com/wp-content/uploads/2021/03/snap-list-all.jpg
|
||||
[4]: https://superuser.com/a/1330590
|
||||
[5]: https://www.debugpoint.com/wp-content/uploads/2021/03/Executing-the-script.jpg
|
||||
[6]: https://www.debugpoint.com/wp-content/uploads/2021/03/Snaps-size-after-cleanup.jpg
|
||||
[7]: https://www.debugpoint.com/2018/07/4-simple-steps-clean-ubuntu-system-linux/
|
||||
[8]: https://www.debugpoint.com/clean-up-flatpak/
|
@ -0,0 +1,106 @@
|
||||
[#]: subject: "How to Clean Up Snap Versions to Free Up Disk Space"
|
||||
[#]: via: "https://www.debugpoint.com/clean-up-snap/"
|
||||
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
如何清理 Snap 版本以释放磁盘空间
|
||||
======
|
||||
|
||||
**这个带有脚本的快速指南有助于清理旧的 snap 版本并释放 Ubuntu 系统中的一些磁盘空间。**
|
||||
|
||||
我在使用 Ubuntu 的测试系统中的磁盘空间不足。因此,我通过 GNOME 的磁盘使用分析器进行调查,以找出哪个包正在消耗宝贵的 SSD 空间。除了通常的缓存和主目录,令我惊讶的是,我发现 Snap 和 Flatpak 消耗了大量的存储空间。
|
||||
|
||||
![Snap 大小 - 清理前][1]
|
||||
|
||||
尽管如此,我始终坚持一个规则:除非必要,否则不要使用 Snap 或 Flatpak。这主要是因为它们的安装尺寸和其他问题。我更喜欢原生 deb 和 rpm 包。多年来,我在这个测试系统中安装和移除了一定数量的 Snap 包。
|
||||
|
||||
卸载后出现问题。Snap 在系统中保留了一些残留文件,一般用户不知道。
|
||||
|
||||
所以我打开了 Snap 文件夹 `/var/lib/snapd/snaps`,发现 Snap 保留了以前安装/卸载的软件包的旧版本。
|
||||
|
||||
例如,在下图中,你可以看到 GNOME 3.28、3.34 和 Wine 都被删除了。但它们还在那里。发生这种情况是因为 Snap 的设计,它在正确卸载后保留已卸载软件包的版本。
|
||||
|
||||
![snaps 目录下的文件][2]
|
||||
|
||||
或者,你可以在终端中使用:
|
||||
|
||||
```
|
||||
snap list --all
|
||||
```
|
||||
|
||||
![snap 列出全部][3]
|
||||
|
||||
对于保留的版本,默认值为 3。这意味着 Snap 会保留每个软件包的三个旧版本,包括活动版本。如果你对磁盘空间没有限制,这是可以的。
|
||||
|
||||
但是对于服务器和其他情况,这很容易遇到成本问题,它会消耗你的磁盘空间。
|
||||
|
||||
但是,你可以使用以下命令轻松修改计数。该值可以在 2 到 20 之间。
|
||||
|
||||
```
|
||||
sudo snap set system refresh.retain=2
|
||||
```
|
||||
|
||||
### 清理 Snap 版本
|
||||
|
||||
在 SuperUser 的一篇文章中,Canonical 的前工程经理 Popey [提供了一个简单的脚本][4],它可以清理旧版本的 Snaps 并保留最新版本。
|
||||
|
||||
这是我们将用来清理 Snap 的脚本。
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
#Removes old revisions of snaps
|
||||
#CLOSE ALL SNAPS BEFORE RUNNING THIS
|
||||
set -eu
|
||||
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
|
||||
while read snapname revision; do
|
||||
snap remove "$snapname" --revision="$revision"
|
||||
done
|
||||
```
|
||||
|
||||
将上面的脚本以 .sh 格式保存在一个目录中(例如 `clean_snap.sh`),赋予它可执行权限并运行。
|
||||
|
||||
```
|
||||
chmod +x clean_snap.sh
|
||||
```
|
||||
|
||||
当我运行脚本后,它减少了很多磁盘空间。该脚本还将显示要删除的包的名称。
|
||||
|
||||
![执行脚本][5]
|
||||
|
||||
![清理后的 Snap 大小][6]
|
||||
|
||||
### 结束语
|
||||
|
||||
对于 Snap 的设计效率如何,人们总是争论不休。许多人说,它的设计是坏的,是臃肿的,是消耗系统资源的。这种说法的某些部分是真实的,我不会否认它。如果实施和加强得当,整个沙盒应用的概念是很好的。我相信,与 Snap 相比,Flatpak 工作做得更好。
|
||||
|
||||
也就是说,我希望这可以帮助你清理一些磁盘空间。尽管它在 Ubuntu 中进行了测试,但它应该适用于所有支持 Snap 的 Linux 发行版。
|
||||
|
||||
此外,请查看我们关于[如何清理 Ubuntu][7] 的指南以及其他步骤。
|
||||
|
||||
最后,如果你要清理 **Flatpak** 应用,请参阅[本指南][8]。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/clean-up-snap/
|
||||
|
||||
作者:[Arindam][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.debugpoint.com/author/admin1/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.debugpoint.com/wp-content/uploads/2021/03/Snap-size-before-cleanup.jpg
|
||||
[2]: https://www.debugpoint.com/wp-content/uploads/2021/03/Files-under-snaps-directory.jpg
|
||||
[3]: https://www.debugpoint.com/wp-content/uploads/2021/03/snap-list-all.jpg
|
||||
[4]: https://superuser.com/a/1330590
|
||||
[5]: https://www.debugpoint.com/wp-content/uploads/2021/03/Executing-the-script.jpg
|
||||
[6]: https://www.debugpoint.com/wp-content/uploads/2021/03/Snaps-size-after-cleanup.jpg
|
||||
[7]: https://www.debugpoint.com/2018/07/4-simple-steps-clean-ubuntu-system-linux/
|
||||
[8]: https://www.debugpoint.com/clean-up-flatpak/
|
Loading…
Reference in New Issue
Block a user