示例
以下是显示其基本用法的示例代码-
while(($name, $passwd, $uid, $gid, $quota,
$comment, $gcos, $dir, $shell) = getpwent()) {
print "Name = $name\n";
print "Password = $passwd\n";
print "UID = $uid\n";
print "GID = $gid\n";
print "Quota = $quota\n";
print "Comment = $comment\n";
print "Gcos = $gcos\n";
print "HOME DIR = $dir\n";
print "Shell = $shell\n";
}
setpwent() ; # Rewind the databse /etc/passwd
while(($name, $passwd, $uid, $gid, $quota,
$comment, $gcos, $dir, $shell) = getpwent()) {
print "Name = $name\n";
print "Password = $passwd\n";
print "UID = $uid\n";
print "GID = $gid\n";
print "Quota = $quota\n";
print "Comment = $comment\n";
print "Gcos = $gcos\n";
print "HOME DIR = $dir\n";
print "Shell = $shell\n";
}
endpwent(); # Closes the database;
尝试一下
执行结果:
Name = root
Password = x
UID = 0
GID = 0
Quota =
Comment =
Gcos = root
HOME DIR = /root
Shell = /bin/bash
Name = daemon
Password = x
UID = 1
GID = 1
Quota =
Comment =
Gcos = daemon
HOME DIR = /usr/sbin
Shell = /usr/sbin/nologin
Name = bin
Password = x
UID = 2
GID = 2
Quota =
Comment =
Gcos = bin
HOME DIR = /bin
Shell = /usr/sbin/nologin
Name = sys
Password = x
UID = 3
GID = 3
Quota =
Comment =
Gcos = sys
HOME DIR = /dev
Shell = /usr/sbin/nologin
Name = sync
Password = x
UID = 4
GID = 65534
Quota =
Comment =
Gcos = sync
HOME DIR = /bin
Shell = /bin/sync
Name = games
Password = x
UID = 5
GID = 60
Quota =
Comment =
Gcos = games
HOME DIR = /usr/games
Shell = /usr/sbin/nologin
Name = man
Password = x
UID = 6
GID = 12
Quota =
Comment =
Gcos = man
HOME DIR = /var/cache/man
Shell = /usr/sbin/nologin
Name = lp
Password = x
UID = 7
GID = 7
Quota =
Comment =
Gcos = lp
HOME DIR = /var/spool/lpd
Shell = /usr/sbin/nologin
Name = mail
Password = x
UID = 8
GID = 8
Quota =
Comment =
Gcos = mail
HOME DIR = /var/mail
Shell = /usr/sbin/nologin
Name = news
Password = x
UID = 9
GID = 9
Quota =
Comment =
Gcos = news
HOME DIR = /var/spool/news
Shell = /usr/sbin/nologin
Name = uucp
Password = x
UID = 10
GID = 10
Quota =
Comment =
Gcos = uucp
HOME DIR = /var/spool/uucp
Shell = /usr/sbin/nologin
Name = proxy
Password = x
UID = 13
GID = 13
Quota =
Comment =
Gcos = proxy
HOME DIR = /bin
Shell = /usr/sbin/nologin
Name = www-data
Password = x
UID = 33
GID = 33
Quota =
Comment =
Gcos = www-data
HOME DIR = /var/www
Shell = /usr/sbin/nologin
Name = backup
Password = x
UID = 34
GID = 34
Quota =
Comment =
Gcos = backup
HOME DIR = /var/backups
Shell = /usr/sbin/nologin
Name = list
Password = x
UID = 38
GID = 38
Quota =
Comment =
Gcos = Mailing List Manager
HOME DIR = /var/list
Shell = /usr/sbin/nologin
Name = irc
Password = x
UID = 39
GID = 39
Quota =
Comment =
Gcos = ircd
HOME DIR = /var/run/ircd
Shell = /usr/sbin/nologin
Name = gnats
Password = x
UID = 41
GID = 41
Quota =
Comment =
Gcos = Gnats Bug-Reporting System (admin)
HOME DIR = /var/lib/gnats
Shell = /usr/sbin/nologin
Name = nobody
Password = x
UID = 65534
GID = 65534
Quota =
Comment =
Gcos = nobody
HOME DIR = /nonexistent
Shell = /usr/sbin/nologin
Name = systemd-timesync
Password = x
UID = 100
GID = 103
Quota =
Comment =
Gcos = systemd Time Synchronization,,,
HOME DIR = /run/systemd
Shell = /bin/false
Name = systemd-network
Password = x
UID = 101
GID = 104
Quota =
Comment =
Gcos = systemd Network Management,,,
HOME DIR = /run/systemd/netif
Shell = /bin/false
Name = systemd-resolve
Password = x
UID = 102
GID = 105
Quota =
Comment =
Gcos = systemd Resolver,,,
HOME DIR = /run/systemd/resolve
Shell = /bin/false
Name = systemd-bus-proxy
Password = x
UID = 103
GID = 106
Quota =
Comment =
Gcos = systemd Bus Proxy,,,
HOME DIR = /run/systemd
Shell = /bin/false
Name = root
Password = x
UID = 0
GID = 0
Quota =
Comment =
Gcos = root
HOME DIR = /root
Shell = /bin/bash
Name = daemon
Password = x
UID = 1
GID = 1
Quota =
Comment =
Gcos = daemon
HOME DIR = /usr/sbin
Shell = /usr/sbin/nologin
Name = bin
Password = x
UID = 2
GID = 2
Quota =
Comment =
Gcos = bin
HOME DIR = /bin
Shell = /usr/sbin/nologin
Name = sys
Password = x
UID = 3
GID = 3
Quota =
Comment =
Gcos = sys
HOME DIR = /dev
Shell = /usr/sbin/nologin
Name = sync
Password = x
UID = 4
GID = 65534
Quota =
Comment =
Gcos = sync
HOME DIR = /bin
Shell = /bin/sync
Name = games
Password = x
UID = 5
GID = 60
Quota =
Comment =
Gcos = games
HOME DIR = /usr/games
Shell = /usr/sbin/nologin
Name = man
Password = x
UID = 6
GID = 12
Quota =
Comment =
Gcos = man
HOME DIR = /var/cache/man
Shell = /usr/sbin/nologin
Name = lp
Password = x
UID = 7
GID = 7
Quota =
Comment =
Gcos = lp
HOME DIR = /var/spool/lpd
Shell = /usr/sbin/nologin
Name = mail
Password = x
UID = 8
GID = 8
Quota =
Comment =
Gcos = mail
HOME DIR = /var/mail
Shell = /usr/sbin/nologin
Name = news
Password = x
UID = 9
GID = 9
Quota =
Comment =
Gcos = news
HOME DIR = /var/spool/news
Shell = /usr/sbin/nologin
Name = uucp
Password = x
UID = 10
GID = 10
Quota =
Comment =
Gcos = uucp
HOME DIR = /var/spool/uucp
Shell = /usr/sbin/nologin
Name = proxy
Password = x
UID = 13
GID = 13
Quota =
Comment =
Gcos = proxy
HOME DIR = /bin
Shell = /usr/sbin/nologin
Name = www-data
Password = x
UID = 33
GID = 33
Quota =
Comment =
Gcos = www-data
HOME DIR = /var/www
Shell = /usr/sbin/nologin
Name = backup
Password = x
UID = 34
GID = 34
Quota =
Comment =
Gcos = backup
HOME DIR = /var/backups
Shell = /usr/sbin/nologin
Name = list
Password = x
UID = 38
GID = 38
Quota =
Comment =
Gcos = Mailing List Manager
HOME DIR = /var/list
Shell = /usr/sbin/nologin
Name = irc
Password = x
UID = 39
GID = 39
Quota =
Comment =
Gcos = ircd
HOME DIR = /var/run/ircd
Shell = /usr/sbin/nologin
Name = gnats
Password = x
UID = 41
GID = 41
Quota =
Comment =
Gcos = Gnats Bug-Reporting System (admin)
HOME DIR = /var/lib/gnats
Shell = /usr/sbin/nologin
Name = nobody
Password = x
UID = 65534
GID = 65534
Quota =
Comment =
Gcos = nobody
HOME DIR = /nonexistent
Shell = /usr/sbin/nologin
Name = systemd-timesync
Password = x
UID = 100
GID = 103
Quota =
Comment =
Gcos = systemd Time Synchronization,,,
HOME DIR = /run/systemd
Shell = /bin/false
Name = systemd-network
Password = x
UID = 101
GID = 104
Quota =
Comment =
Gcos = systemd Network Management,,,
HOME DIR = /run/systemd/netif
Shell = /bin/false
Name = systemd-resolve
Password = x
UID = 102
GID = 105
Quota =
Comment =
Gcos = systemd Resolver,,,
HOME DIR = /run/systemd/resolve
Shell = /bin/false
Name = systemd-bus-proxy
Password = x
UID = 103
GID = 106
Quota =
Comment =
Gcos = systemd Bus Proxy,,,
HOME DIR = /run/systemd
Shell = /bin/false