WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: If you want to know the Raspberry Pi model / version / cores  (Read 1723 times)

Offline Pengo

  • Newbie
  • *
  • Posts: 30
If you want to know the Raspberry Pi model / version / cores
« on: March 12, 2020, 01:43:55 PM »
Save this in a script.

Code: [Select]
#!/bin/bash

export myvar=`cat /proc/cpuinfo |grep Revision | cut -d : -f 2 | tr -d "[:blank:]"`
#echo Revision = $myvar

case "$myvar" in
0002) echo Raspberry PI B v1.0 256MB RAM made by Egoman;;
0003) echo Raspberry PI B v1.0 256MB RAM made by Egoman;;
0004) echo Raspberry PI B v2.0 256MB RAM made by Sony UK;;
0005) echo Raspberry PI B v2.0 256MB RAM made by Qisda;;
0006) echo Raspberry PI B v2.0 256MB RAM made by Egoman;;
0007) echo Raspberry PI A v2.0 256MB RAM made by Egoman;;
0008) echo Raspberry PI A v2.0 256MB RAM made by Sony UK;;
0009) echo Raspberry PI A v2.0 256MB RAM made by Qisda;;
000d) echo Raspberry PI B v2.0 512MB RAM made by Egoman;;
000e) echo Raspberry PI B v2.0 512MB RAM made by Sony UK;;
000f) echo Raspberry PI B v2.0 512MB RAM made by Egoman;;
0010) echo Raspberry PI B+ v1.2 512MB RAM made by Sony UK;;
0011) echo Raspberry PI CM1 v1.0 512MB RAM made by Sony UK;;
0012) echo Raspberry PI A+ v1.1 256MB RAM made by Sony UK;;
0013) echo Raspberry PI B+ v1.2 512MB RAM made by Embest;;
0014) echo Raspberry PI CM1 v1.0 512MB RAM made by Embest;;
0015) echo Raspberry PI A+ v1.1 256MB/512MB RAM made by Embest;;
900021) echo Raspberry PI A+ v1.1 512MB RAM made by Sony UK;;
900032) echo Raspberry PI B+ v1.2 512MB RAM made by Sony UK;;
900092) echo Raspberry PI Zero v1.2 512MB RAM made by Sony UK;;
900093) echo Raspberry PI Zero v1.3 512MB RAM made by Sony UK;;
9000c1) echo Raspberry PI Zero W v1.1 512MB RAM made by Sony UK;;
9020e0) echo Raspberry PI 3A+ v1.0 512MB RAM made by Sony UK;;
920092) echo Raspberry PI Zero v1.2 512MB RAM made by Embest;;
920093) echo Raspberry PI Zero v1.3 512MB RAM made by Embest;;
900061) echo Raspberry PI CM v1.1 512MB RAM made by Sony UK;;
a01040) echo Raspberry PI 2B v1.0 1GB RAM made by Sony UK;;
a01041) echo Raspberry PI 2B v1.1 1GB RAM made by Sony UK;;
a02082) echo Raspberry PI 3B v1.2 1GB RAM made by Sony UK;;
a020a0) echo Raspberry PI CM3 v1.0 1GB RAM made by Sony UK;;
a020d3) echo Raspberry PI 3B+ v1.3 1GB RAM made by Sony UK;;
a02042) echo Raspberry PI 2B with BCM2837 v1.2 1GB RAM made by Sony UK;;
a21041) echo Raspberry PI 2B v1.1 1GB RAM made by Embest;;
a22042) echo Raspberry PI 2B with BCM2837 v1.2 1GB RAM made by Embest;;
a22082) echo Raspberry PI 3B v1.2 1GB RAM made by Embest;;
a220a0) echo Raspberry PI CM3 v1.0 1GB RAM made by Embest;;
a32082) echo Raspberry PI 3B v1.2 1GB RAM made by Sony Japan;;
a52082) echo Raspberry PI 3B v1.2 1GB RAM made by Stadium;;
a22083) echo Raspberry PI 3B v1.3 1GB Embest;;
a02100) echo Raspberry PI CM3+ v1.0 1GB RAM made by Sony UK;;
a03111) echo Raspberry PI 4B v1.1 1GB RAM made by Sony UK;;
b03111) echo Raspberry PI 4B v1.1 2GB RAM made by Sony UK;;
c03111) echo Raspberry PI 4B v1.1 4GB RAM made by Sony UK;;
c03112) echo Raspberry PI 4B v1.2 4GB RAM made by Sony UK;;
*)      echo Unknown Revision -$myvar-
esac

cat /proc/cpuinfo |grep Hardware
cat /proc/cpuinfo |grep Serial
cat /proc/meminfo |grep MemTotal
echo Number of Cores:
cat /proc/cpuinfo |grep processor |wc -l

    [EDIT]: Fixed typo. Changed  #/bin/bash  to  #!/bin/bash.  Rich
« Last Edit: March 12, 2020, 04:08:12 PM by Rich »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: If you want to know the Raspberry Pi model / version / cores
« Reply #1 on: March 12, 2020, 01:56:38 PM »
Hi Pengo
If you want the  Number of Cores:  message and the number to appear on the same line, you can do this:
Code: [Select]
echo Number of Cores: `cat /proc/cpuinfo |grep processor |wc -l`The  `  is a back tick, not a single quote. It is usually found on the  ~  key. There is one before  cat  and one after  wc -l.

or that:
Code: [Select]
echo -n Number of Cores:
cat /proc/cpuinfo |grep processor |wc -l
This version suppresses the linefeed from the  echo  command. You can add a trailing space to  Cores:  to separate it from the number.

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: If you want to know the Raspberry Pi model / version / cores
« Reply #2 on: March 12, 2020, 03:53:12 PM »
hi Pengo,

Cool script.

A new version of the RPi4B2 was released:

Code: [Select]
b03112
4B
1.2
2GB
Sony UK

https://github.com/raspberrypi/documentation/blob/master/hardware/raspberrypi/revision-codes/README.md

and the first line should be:

Code: [Select]
#!/bin/sh
Leaving the ! out means it is just a comment and the bash shell is not loaded by default.

regards
Greg

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: If you want to know the Raspberry Pi model / version / cores
« Reply #3 on: March 12, 2020, 04:06:30 PM »
Hi Greg Erskine
... and the first line should be:

Code: [Select]
#!/bin/sh
Leaving the ! out means it is just a comment and the bash shell is not loaded by default. ...
I missed that, nice catch. I'll fix it for him.

Offline Pengo

  • Newbie
  • *
  • Posts: 30
Re: If you want to know the Raspberry Pi model / version / cores
« Reply #4 on: March 12, 2020, 04:21:52 PM »
Updated version (including the suggested improvements and addition of the new board, thanks!):

Code: [Select]
#!/bin/sh

export myvar=`cat /proc/cpuinfo |grep Revision | cut -d : -f 2 | tr -d "[:blank:]"`
#echo Revision = $myvar

case "$myvar" in
0002) echo Raspberry PI B v1.0 256MB RAM made by Egoman;;
0003) echo Raspberry PI B v1.0 256MB RAM made by Egoman;;
0004) echo Raspberry PI B v2.0 256MB RAM made by Sony UK;;
0005) echo Raspberry PI B v2.0 256MB RAM made by Qisda;;
0006) echo Raspberry PI B v2.0 256MB RAM made by Egoman;;
0007) echo Raspberry PI A v2.0 256MB RAM made by Egoman;;
0008) echo Raspberry PI A v2.0 256MB RAM made by Sony UK;;
0009) echo Raspberry PI A v2.0 256MB RAM made by Qisda;;
000d) echo Raspberry PI B v2.0 512MB RAM made by Egoman;;
000e) echo Raspberry PI B v2.0 512MB RAM made by Sony UK;;
000f) echo Raspberry PI B v2.0 512MB RAM made by Egoman;;
0010) echo Raspberry PI B+ v1.2 512MB RAM made by Sony UK;;
0011) echo Raspberry PI CM1 v1.0 512MB RAM made by Sony UK;;
0012) echo Raspberry PI A+ v1.1 256MB RAM made by Sony UK;;
0013) echo Raspberry PI B+ v1.2 512MB RAM made by Embest;;
0014) echo Raspberry PI CM1 v1.0 512MB RAM made by Embest;;
0015) echo Raspberry PI A+ v1.1 256MB/512MB RAM made by Embest;;
900021) echo Raspberry PI A+ v1.1 512MB RAM made by Sony UK;;
900032) echo Raspberry PI B+ v1.2 512MB RAM made by Sony UK;;
900092) echo Raspberry PI Zero v1.2 512MB RAM made by Sony UK;;
900093) echo Raspberry PI Zero v1.3 512MB RAM made by Sony UK;;
9000c1) echo Raspberry PI Zero W v1.1 512MB RAM made by Sony UK;;
9020e0) echo Raspberry PI 3A+ v1.0 512MB RAM made by Sony UK;;
920092) echo Raspberry PI Zero v1.2 512MB RAM made by Embest;;
920093) echo Raspberry PI Zero v1.3 512MB RAM made by Embest;;
900061) echo Raspberry PI CM v1.1 512MB RAM made by Sony UK;;
a01040) echo Raspberry PI 2B v1.0 1GB RAM made by Sony UK;;
a01041) echo Raspberry PI 2B v1.1 1GB RAM made by Sony UK;;
a02082) echo Raspberry PI 3B v1.2 1GB RAM made by Sony UK;;
a020a0) echo Raspberry PI CM3 v1.0 1GB RAM made by Sony UK;;
a020d3) echo Raspberry PI 3B+ v1.3 1GB RAM made by Sony UK;;
a02042) echo Raspberry PI 2B with BCM2837 v1.2 1GB RAM made by Sony UK;;
a21041) echo Raspberry PI 2B v1.1 1GB RAM made by Embest;;
a22042) echo Raspberry PI 2B with BCM2837 v1.2 1GB RAM made by Embest;;
a22082) echo Raspberry PI 3B v1.2 1GB RAM made by Embest;;
a220a0) echo Raspberry PI CM3 v1.0 1GB RAM made by Embest;;
a32082) echo Raspberry PI 3B v1.2 1GB RAM made by Sony Japan;;
a52082) echo Raspberry PI 3B v1.2 1GB RAM made by Stadium;;
a22083) echo Raspberry PI 3B v1.3 1GB Embest;;
a02100) echo Raspberry PI CM3+ v1.0 1GB RAM made by Sony UK;;
a03111) echo Raspberry PI 4B v1.1 1GB RAM made by Sony UK;;
b03111) echo Raspberry PI 4B v1.1 2GB RAM made by Sony UK;;
b03112) echo Raspberry PI 4B v1.2 2GB RAM made by Sony UK;;
c03111) echo Raspberry PI 4B v1.1 4GB RAM made by Sony UK;;
c03112) echo Raspberry PI 4B v1.2 4GB RAM made by Sony UK;;
*)      echo Unknown Revision -$myvar-
esac

cat /proc/cpuinfo |grep Hardware
cat /proc/cpuinfo |grep Serial
cat /proc/meminfo |grep MemTotal
echo "Number of Cores : "`cat /proc/cpuinfo |grep processor |wc -l`