I need to store the current IP adress of my Raspberry Pi into a file. Can someone tell me how to do this?

The goal is to create a file in /var/www/ipadress.txt with this content:

$ ifconfig
eth0      Link encap:Ethernet  Hardware Adresse b8:27:eb:7c:ce:18
          inet Adresse:  Bcast:  Maske:
          RX packets:1762 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1044 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000
          RX bytes:267534 (261.2 KiB)  TX bytes:233261 (227.7 KiB)

I need the part:


I found that this command will give you the IP address only:

$ /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

To output it to a file:

$ /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' > "/var/www/ipadress.txt"
  • 1
    i had to change it to: $ /sbin/ifconfig eth0 | grep 'inet Adresse:' | cut -d: -f2 | awk '{ print $1}' > "/var/www/ipadress.txt" because im using the raspberry in german language – s3bi Nov 2 '13 at 23:38

language independent version:

ifconfig | grep -o "\([0-9]\+\.\)\+[0-9]\+" | head -n 1

or, as it was noted in another question

hostname -I

might do the trick as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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