#!/usr/bin/python3
#coding:utf8
with open("/etc/passwd") as f:
result = {"system":0,"local":0}
for line in f:
args = line.split(":")
d = dict(
username = args[0],
passwd = args[1],
uid = args[2],
gid = args[3],
description = args[4],
homepath = args[5],
script = args[6]
)
uid = int(d["uid"])
if uid in range(500):
result["system"] += 1
elif uid >= 500:
result["local"] += 1
print(result)
执行结果:

本文通过Python脚本解析了Linux系统中的/etc/passwd文件,详细介绍了如何读取和分类用户信息,将用户分为系统用户和本地用户,并统计各自数量。
539

被折叠的 条评论
为什么被折叠?



