How can I find the serial number of my Apple Keyboard USB on a mac programmatically from the terminal?
I don't think you can. The information that you can get is available via System Profiler: system_profiler SPUSBDataType, which on my Macbook returns:

    Apple Internal Keyboard / Trackpad:

      Product ID: 0x0259
      Vendor ID: 0x05ac  (Apple Inc.)
      Version: 2.24
      Speed: Up to 12 Mb/sec
      Manufacturer: Apple Inc.
      Location ID: 0x14400000 / 3
      Current Available (mA): 1000
      Current Required (mA): 40
      Extra Operating Current (mA): 0
      Built-In: Yes