How to list file names and their contents

Use basic Linux utilities to list file names and their contents.

Display file names including their contents in /proc/pressure/ directory.

$ awk '{printf "%s^%s\n", FILENAME, $0}' /proc/pressure/*  | column -s "^" -t
/proc/pressure/cpu     some avg10=1.52 avg60=1.56 avg300=1.88 total=9032793664
/proc/pressure/io      some avg10=0.00 avg60=0.00 avg300=0.00 total=1257329887
/proc/pressure/io      full avg10=0.00 avg60=0.00 avg300=0.00 total=1047421540
/proc/pressure/memory  some avg10=0.00 avg60=0.00 avg300=0.00 total=66419711
/proc/pressure/memory  full avg10=0.00 avg60=0.00 avg300=0.00 total=49989988

Use sudo to find temp files inside /sys/class/thermal directory to display file names and the first line of their contents.

$ sudo bash -c "awk 'FNR==1{printf \"%s^%s\n\", FILENAME, \$0}' \$(find /sys/class/thermal/ -maxdepth 2 -follow -name temp 2>/dev/null) | column -s "^" -t"
/sys/class/thermal/thermal_zone2/temp  47000
/sys/class/thermal/thermal_zone0/temp  27800
/sys/class/thermal/thermal_zone1/temp  29800

Use sudo to display file names including the first line of their contents in /sys/class/net/eno1/ directory.

$ sudo bash -c "awk 'FNR==1{printf \"%s^%s\n\", FILENAME, \$0}' /sys/class/net/eno1/* 2>/dev/null | column -s "^" -t"
/sys/class/net/eno1/addr_assign_type    0
/sys/class/net/eno1/address             f8:b1:56:41:3b:51
/sys/class/net/eno1/addr_len            6
/sys/class/net/eno1/broadcast           ff:ff:ff:ff:ff:ff
/sys/class/net/eno1/carrier             1
/sys/class/net/eno1/carrier_changes     8
/sys/class/net/eno1/carrier_down_count  4
/sys/class/net/eno1/carrier_up_count    4
/sys/class/net/eno1/dev_id              0x0
/sys/class/net/eno1/dev_port            0
/sys/class/net/eno1/dormant             0
/sys/class/net/eno1/duplex              full
/sys/class/net/eno1/flags               0x1003
/sys/class/net/eno1/gro_flush_timeout   0
/sys/class/net/eno1/ifindex             2
/sys/class/net/eno1/iflink              2
/sys/class/net/eno1/link_mode           0
/sys/class/net/eno1/mtu                 1500
/sys/class/net/eno1/name_assign_type    4
/sys/class/net/eno1/netdev_group        0
/sys/class/net/eno1/operstate           up

It comes in handy at times.