linux-clean

1. 清理文件系统工具
 1.1 Disk usage display
 1.2 Disk cleaning
2. 软件包清理
 2.1 Package cache 包缓存
 2.2 Unused packages (orphans) 孤儿包
 2.3 Pacman包管理器的使用参考
3. (借助1.2 Disk cleaning的工具)
 3.1 Old configuration files
 3.2 Broken symlinks
 3.3 使用BleachBit清理Home目录
4. 多语言
5. pkglist

1. 清理文件系统工具

https://wiki.archlinux.org/index.php/System_maintenance#Clean_the_filesystem
在寻找要删除的文件时,重要的是找到占用磁盘空间最多的文件。可以在以下位置找到有助于此目的的程序:

1.1 Disk usage display

应用程序列表#磁盘使用情况显示。https://wiki.archlinux.org/index.php/List_of_applications#Disk_usage_display

1.2 Disk cleaning

应用程序列表#磁盘清洁。https://wiki.archlinux.org/index.php/List_of_applications#Disk_cleaning

2. 软件包清理

2.1 Package cache 包缓存

https://wiki.archlinux.org/index.php/System_maintenance#Package_cache
Remove unwanted .pkg files from /var/cache/pacman/pkg/ to free up disk space.
See Pacman#Cleaning the package cache for more information.
https://wiki.archlinux.org/index.php/Pacman#Cleaning_the_package_cache
$ sudo paccache -rk1
$ sudo pacman -Sc

2.2 Unused packages (orphans) 孤儿包

Remove unused packages from the system to free up disk space and simplify maintenance.
See Pacman/Tips and tricks#Removing unused packages (orphans) for details.
https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#Removing_unused_packages_(orphans)
$ sudo pacman -Qqdt | sudo pacman -Rs -
$ sudo pacman -Rns $(pacman -Qtdq)

2.3 Pacman包管理器的使用参考

pacman-help; Arch-pacman-Tips-And-Tricks; Arch Linux 软件包的查询及清理; archlinux-pacdiff

3. (借助1.2 Disk cleaning的工具)

3.1 Old configuration files

https://wiki.archlinux.org/index.php/System_maintenance#Old_configuration_files
旧的配置文件可能与较新的软件版本冲突,或者随着时间的推移而损坏。定期删除不需要的配置,尤其是在主文件夹和中~/.config。出于类似原因,在安装之间共享主文件夹时要小心。
查找以下文件夹:
~/.config/ -应用程序存储其配置的位置
~/.cache/ -某些程序的缓存大小可能会增加
~/.local/share/ -旧文件可能躺在那里
有关更多信息,请参见XDG基本目录支持。https://wiki.archlinux.org/index.php/XDG_Base_Directory_support
为了使主目录免受在错误位置创建的临时文件的影响,最好管理一系列不需要的文件并定期删除它们,例如,使用rmshit.py。
rmlint可用于查找并有选择地删除重复文件,空文件,递归空目录和损坏的符号链接。

3.2 Broken symlinks

https://wiki.archlinux.org/index.php/System_maintenance#Broken_symlinks
旧的断开的符号链接可能位于您的系统中。您应该删除它们。可以在以下链接找到实现此目标的示例。但是,您不应盲目删除所有断开的符号链接,因为其中某些符号链接可以达到目的。
https://unix.stackexchange.com/questions/34248/how-can-i-find-broken-symlinks
http://www.commandlinefu.com/commands/view/8260/find-broken-symlinks
要快速列出系统中所有损坏的符号链接,请使用:
  $ sudo find / -xtype l -print
然后检查并从该列表中删除不必要的条目。

3.3 使用BleachBit清理Home目录

  1. 打开BleachBit, 左侧勾选需要清理的项目;
  2. 点击上方[Preview]预览, 程序会扫描相关目录并列出认为可以删除的文件列表;
  3. 通过滚动条浏览没有问题, 就可以点击上方的[Clean]清理这些文件了.

注: 第一次使用, 建议不要全选, 逐个选择项目,扫描出的文件列表不会太长, 方便勘查. > [Preview]预览 > [Clean]清理

4. 多语言

https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#Installing_only_content_in_required_languages
仅安装所需语言的内容
许多软件包尝试安装多种语言的文档和翻译。某些程序旨在删除此类不必要的文件,例如localepurgeAUR,它在安装软件包后运行以删除不需要的语言环境文件。通过pacman.conf中的NoExtract指令提供了一种更直接的方法,该方法可以防止安装这些文件。
警告:一些用户指出,即使在Xorg下,删除语言环境也会导致意想不到的后果。
下面的示例安装英语(美国)文件,或完全不安装:
/etc/pacman.conf
NoExtract = usr/share/help/* !usr/share/help/en*
NoExtract = usr/share/gtk-doc/html/*
NoExtract = usr/share/locale/* usr/share/X11/locale/* usr/share/i18n/* opt/google/chrome/locales/* !usr/share/X11/locale/C/*
NoExtract = !*locale*/en*/* !usr/share/i18n/charmaps/UTF-8.gz !usr/share/*locale*/locale.*
NoExtract = !usr/share/*locales/en_?? !usr/share/*locales/i18n* !usr/share/*locales/iso*
NoExtract = !usr/share/*locales/trans*
NoExtract = usr/share/qt4/translations/*
NoExtract = usr/share/man/* !usr/share/man/man*
NoExtract = usr/share/vim/vim*/lang/*
NoExtract = usr/lib/libreoffice/help/en-US/*

5. pkglist

https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#List_of_installed_packages
保留所有明确安装的软件包的列表对于例如备份系统或加快在新系统上的安装非常有用:
$ pacman -Qqe > pkglist.txt
要从以前保存的软件包列表中安装软件包,而又不重新安装已经是最新的软件包,请运行:
$ sudo pacman -S --needed - < pkglist.txt
但是,列表中可能存在诸如来自AUR或本地安装的外部软件包。要从列表中过滤出外部软件包,可以按如下方式丰富前一个命令行:
$ sudo pacman -S --needed $(comm -12 <(pacman -Slq | sort) <(sort pkglist.txt))
最终,要确保系统中已安装的软件包与列表匹配,并删除其中未提及的所有软件包:
$ sudo pacman -Rsu $(comm -23 <(pacman -Qq | sort) <(sort pkglist.txt))

列出软件包中所有更改的文件
# paccheck --md5sum --quiet
重新安装所有软件包
# pacman -Qqn | pacman -S -

6. 更多参考阅读

https://www.ibm.com/developerworks/cn/linux/1310_caoyq_linuxdelete/index.html
给 Linux 系统“减肥” 201310

查找重复文件-fdupes和fslint的比较 |2012年6月2日-09:02 |drad
http://www.adercon.com/ac/node/56

如何查找(和删除)重复文件 2017-11-10
https://ubuntuqa.com/article/453.html
https://askubuntu.com/questions/3865/how-to-find-and-delete-duplicate-files
https://qastack.cn/ubuntu/3865/how-to-find-and-delete-duplicate-files

https://qastack.cn/superuser/801746/how-to-deduplicate-40tb-of-data
find -not -empty -type f -printf "%s " | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate

https://rmlint.readthedocs.io/en/latest/cautions.html
注意事项(或为什么很难编写dupefinder)
本节介绍安全删除重复项的良好做法。它无意与专门相关rmlint。它包括有关重复检测的一般性讨论,并举例说明了重复发现者可能会陷入的陷阱。本部分不仅对重复查找者的开发人员有用,而且对寻求有关重复数据删除最佳实践的用户也很有帮助。
删除重复项时的良好做法...

https://rmlint.readthedocs.io/en/latest/benchmarks.html
基准
该页面包含我们的基准测试套件针对当前版本渲染的图像。基准套件里面,rmlint被质疑与其他流行的一些鲜为人知的重复的发现者。除此之外,还使用了一个非常笨拙的重复查找baseline.py程序,该程序用于查看程序将盲目地哈希找到的所有文件的速度。幸运的是,这些程序都没有 那么慢。我们将在图上进行一些说明,尽管我们将重点放在上rmlint。当然,您可以自由地解释不同的事物,也可以 在自己的计算机上重新运行基准测试。图中给出了每个程序的确切版本。

原文地址:https://www.cnblogs.com/sztom/p/13222744.html