Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where can I find the serial number of the Raspberry Pi I am currently using?

share|improve this question
is the serial number printed on the device or is it only available through software? I see there is a sticker on the device but I don't think that it is related to the serial number. It would be nice to know the ID of the device without having to power it on and connect it. – Scoop Oct 4 '12 at 21:54
@AlexisK It's only available in software. – Alex Chamberlain Oct 8 '12 at 10:21
Correct, there doesn't seem to be any relation with the sticker and serial number. I've read the sticker of a number of Pi's and tried to decode it. While Raspberry probably has internal lists connecting both, it doesn't seem that there is any way to calculate the serial or MAC from it. – EDP Aug 15 '15 at 9:24
up vote 35 down vote accepted

The serial number can be found in /proc/cpuinfo; for example,

 pi@raspberrypi:~$ cat /proc/cpuinfo
 Processor       : ARMv6-compatible processor rev 7 (v6l)
 BogoMIPS        : 697.95
 Features        : swp half thumb fastmult vfp edsp java tls
 CPU implementer : 0x41
 CPU architecture: 7
 CPU variant     : 0x0
 CPU part        : 0xb76
 CPU revision    : 7

 Hardware        : BCM2708
 Revision        : 1000002
 Serial          : 000000000000000d


You can use very basic bash piping

cat /proc/cpuinfo | grep Serial | cut -d ':' -f 2

When you see the result it will initially have a leading space, but once it's assigned to a variable the leading space disappears like magic.

For example:

SERIAL="$(cat /proc/cpuinfo | grep Serial | cut -d ':' -f 2)"
echo $SERIAL


In Bash, it is very simple to extract... by using Perl. Use

cat /proc/cpuinfo | perl -n -e '/^Serial[ ]*: ([0-9a-f]{16})$/ && print "$1\n"'

For example,

$ cat cpuinfo | perl -n -e '/^Serial[ ]*: ([0-9a-f]{16})$/ && print "$1\n"'


Raspberry Spy provides a very useful Python example.

def getserial():
  # Extract serial from cpuinfo file
  cpuserial = "0000000000000000"
    f = open('/proc/cpuinfo','r')
    for line in f:
      if line[0:6]=='Serial':
        cpuserial = line[10:26]
    cpuserial = "ERROR000000000"

  return cpuserial


  1. Licence key product pages
  2. Raspberry Spy: Getting Your Raspberry Pi Serial Number Using Python
share|improve this answer
Perl will accept filenames as arguments. It's not necessary to use cat. – Dennis Williamson Oct 4 '12 at 21:18
the last 6 digits of my serial number are the same as the last 6 digits of my MAC address. Is this true for you? – Scoop Oct 4 '12 at 21:51
@AlexisK: It's true for me. – Dennis Williamson Oct 4 '12 at 23:52
< redirection also works, so it's a useless use of cat. – XTL Oct 5 '12 at 6:21
@XTL I prefer to use pipes than input redirection; it flows nicely. Just personal preference. – Alex Chamberlain Oct 5 '12 at 6:30


Using grep:

grep -Po '^Serial\s*:\s*\K[[:xdigit:]]{16}' /proc/cpuinfo


Using pure Bash without using any external utilities:

while read -r line
    if [[ $line =~ $pattern ]]
        echo "${BASH_REMATCH[1]}"
done < /proc/cpuinfo

The output of either of the above is the same.

share|improve this answer
this is the only one that worked for me – cwd Mar 26 '14 at 19:36


Since this turned out to be some kind of "how many ways can you get the serial" here is the awk version

  awk '/^Serial\s*:\s/{print $3}' /proc/cpuinfo
share|improve this answer

Using awk:

cat /proc/cpuinfo | grep Serial | awk ' {print $3}'
share|improve this answer
That's a nice example of UUOC. Could be simply written awk '/Serial/{print $3}' /proc/cpuinfo – ripat Feb 4 at 17:30
grep -i serial /proc/cpuinfo | cut -d : -f2
share|improve this answer
programming golf is not encouraged on the web-site, because it's very difficult to follow your answer for beginners, especially if you don't write any explanation or detailed comment. – lenik May 10 '14 at 8:03
I'd oppose to call this answer "programming golf" comparing to even more cryptic one like "Bash/Awk". Actually, I intended to uplift this answer for sake of equality, but after running it on my PI and comparing to other version, won't do it because must admit, this answer is not giving precise output by inserting extra leading space. PS: I won't minus it too though – Van Jone Mar 25 '15 at 23:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.