Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I want to obtain the currently connected wifi networks ssid in a bash script. I am trying to write a backup script where the script will perform a backup to a NAS server if it's connected to my home wifi network. I have looked into the ip route command but it only returns some basic information - enter image description here

share|improve this question

5 Answers 5

up vote 2 down vote accepted

The following should provide what you are looking for assuming you are connected using 1 wireless device:

nmcli -t -f ssid dev wifi| cut -d\' -f2


nmcli dev wifi|grep yes| cut -d\' -f2
share|improve this answer
it's returning all the connected networks. Can I find only the connected network? – Chan Apr 18 '13 at 6:45
Try it like this and let me know: nmcli -t -f active,ssid dev wifi| cut -d\' -f2 – Luis Alvarado Apr 18 '13 at 6:46
Still returning many results – Chan Apr 18 '13 at 6:47
Can you pastebin what you are seeing as output? – Luis Alvarado Apr 18 '13 at 6:48
iwgetid -r


iwgetid wlan0 -r
share|improve this answer

How 'bout iwconfig wlan0 | sed -e '/ESSID/!d' -e 's/.*ESSID:"/"/'?

share|improve this answer

This command returns the SSID of the connected wireless adapter (assuming you only have one).

iwconfig | grep ESSID | sed -e 's/.*ESSID:"\(.*\)".*/\1/'

It also print warning on the terminal but on stderr so it doesn't matter

remi@host~$id:~$ id=$(iwconfig | grep ESSID | sed -e 's/.*ESSID:"\(.*\)".*/\1/')
eth0      no wireless extensions.
lo        no wireless extensions.
virbr0    no wireless extensions.
tap0      no wireless extensions.

remi@host:~$ echo $id
share|improve this answer
nmcli -t -f NAME connection show --active
  • -t Makes the output 'terse' so no headers
  • -f NAME Shows only the ssid
  • --active Shows only the active connections
share|improve this answer

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.