mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-15 06:12:59 +00:00
Add getpwent() example to perl
This commit is contained in:
parent
52e621be4e
commit
08a6f38fe7
@ -58,3 +58,11 @@ perl -e 'print("$<:" . (split(" ", $)))[0] . "\n")'
|
||||
# You might spot some printable strings, such as 'LILO' or 'GRUB', if you've
|
||||
# also stored your bootloader on the MBR of the storage device (non-UEFI).
|
||||
perl -e 'open(my $FH, "</dev/sda"); read($FH, my $Data, 512); close($FH); print("$Data\n")'
|
||||
|
||||
# Create a simple table of users within your system. This example demonstrates
|
||||
# the use of the `getpwent()` subroutine, which, upon each execution, holds an
|
||||
# array of each field in each line within the '/etc/passwd' file.
|
||||
printf("%-15s %-5s %-5s %-s\n", 'USERNAME', 'UID', 'GID', 'HOME');
|
||||
while (my @Data = getpwent()) {
|
||||
printf("%-15s %-5s %-5s %-s\n", $Data[0], $Data[2], $Data[3], $Data[7])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user