Which Intel "generation" is my Mac's CPU?
You can get the processor generation by running the following command in Terminal:

sysctl machdep.cpu.brand_string


If the output contains a dash and a number after your "iX"-Core model, the first digit after the slash is the processor generation. See: Intel® Processor Numbers: Laptop, Desktop, and Mobile Device

Examples:


2nd Generation : Intel(R) Core(TM) i5-2760QM
5th Generation : Intel(R) Core(TM) i7-5257U CPU @ 2.70GHz
6th Generation : Intel(R) Core(TM) m3-6Y30
8th Generation : Intel(R) Core(TM) i5-8350U


If the dash is missing, it's first generation (or a different CPU altogether), e.g.:


1st Generation : Intel(R) Core(TM) i5 CPU 750 @ 2.67GHz




Different approach:

sysctl machdep.cpu


Gives you detailed CPU information.

From machdep.cpu.extmodel:


0 for a "Intel(R) Core(TM)2 CPU T7400 @ 2.16GHz"
1 for a late 2009 iMac-i5 "Intel(R) Core(TM) i5 CPU 750 @ 2.67GHz"
1 for a Mac Pro (Mid 2010) "Intel(R) Xeon(R) CPU W3530 @ 2.80GHz" 
4 for a 2015 macbook pro (4th generation)
4 for a "Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz" (4th generation)


Although it's inconsistent:


4 for a 2016 macbook "Intel(R) Core(TM) m3-6Y30" (6th generation) 
5 for a "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz" (6th generation)


From fsb's comment below: 


  According to Intel, the generation is the first number after the "-" (in machdep.cpu.brand_string)