Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
删除 kde-applications 中属于教育或游戏分类的应用,需要 root 权限,使用需谨慎
import subprocess
import glob
def is_need_remove(file_path):
with open(file_path, 'r') as f:
content = f.readlines()
for line in content:
if line.split("=")[0] == "Categories":
categories = line.split("=")[1]
# 如果分类字段里有 Education 或 Game,那么认为是需要删除的
if "Education" in categories or "Game" in categories:
return True
return False
for desktop_file in glob.glob("/usr/share/applications/*"):
if is_need_remove(desktop_file):
query_command = "pacman -Qoq " + desktop_file
# 查询该 desktop 文件属于哪个软件包
package_name =, shell=True, stdout = subprocess.PIPE)
package_name = package_name.stdout.decode("utf-8").strip()
remove_command = "pacman -Rsc " + package_name + " --noconfirm"
# 移除软件包
result =, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment