90

Neither iwconfig nor iwlist seem to be able to do this for me.

7 Answers 7

152

iwgetid provides the ssid

iwgetid -r gives just the name.

In a Bash script try something like myssid=$(iwgetid -r) to put it in a variable

1
  • 4
    Thanks! Looks much better than the commonly recommended iw/iwlan+sed/grep solutions.
    – Rob W
    Mar 19, 2014 at 12:37
34

Run nm-tool | grep \*. That should show just the line with the SSID you are connected to.

Edit: The nm-tool utility had ceased to exist, so in 16.04 and newer releases, please use any of the methods suggested by my esteemed colleagues below.

For example: nmcli -t -f active,ssid dev wifi | egrep '^yes' | cut -d\' -f2 works well.

5
  • Thanks that's exactly what I needed. To get just the name:nm-tool |grep --only-matching '*[^ ][^:]*' |sed 's/^*//' Mar 29, 2012 at 16:09
  • 3
    nmcli -t -f active,ssid dev wifi is easier to parse. The ssid is unfortunately encapsulated in some useless quotes though.
    – geirha
    Mar 29, 2012 at 16:48
  • 4
    Or: nmcli -t -f active,ssid dev wifi | egrep '^yes' | cut -d\' -f2 (which will work as long as the SSID doesn't contain any ' characters) Mar 30, 2012 at 7:43
  • 2
    Ubuntu 16.10: $ nm-tool | grep \* No command 'nm-tool' found, did you mean: Command 'dm-tool' from package 'lightdm' (main) nm-tool: command not found Scott's command works though
    – Ads20000
    Jan 16, 2017 at 13:21
  • 3
    $ nmcli -t -f active,ssid dev wifi | egrep '^yes' | cut -d\: -f2 is the command I just used on Ubuntu 17.04. Jan 4, 2018 at 23:42
32

Although the question has already been answered, the iwconfig tool does display the ESSID of the currently connected Wifi network. Perhaps it does not work with connections managed through NetworkManager but it works with interfaces managed through ifup/ifdown:

iwconfig | grep wlan0

lists:

wlan0     IEEE 802.11bgn  ESSID:"ahoi"
1
  • 1
    Typing iwconfig only can do the purpose too :-) thanks for sharing this command :-)
    – Suhaib
    Mar 30, 2013 at 18:22
16

None of the prior answers worked for me unfortunately. I was however able to get the details via

$ sudo iw dev wlan0 info

and got

Interface wlan0
    ifindex 5
    wdev 0x1
    addr **:**:*:*:*:*
    ssid *****
    type AP
    wiphy 0
    channel 2 (2417 MHz), width: 20 MHz, center1: 2417 MHz
1
8

You can also use the iw tool (from the iw package) to obtain the WiFi link parameters which includes the currently associated SSID - e.g for wlan0:

iw dev wlan0 link
5
nmcli -t -f name connection show --active

shows the same output without listing all available SSIDs in vicinity so without delay. if more network interfaces are available and active can be parsed by interface name like so:

nmcli -t -f name,device connection show --active | grep wlp3s0 | cut -d\: -f1
1
  • Useful for users who use networkmanager (like me) Jul 23, 2020 at 21:48
3

simply use this command to get only the ssid "NAME"

iw dev wlan0 info | grep ssid | awk '{print $2}'

Where wlan0 is the interface for your Wi-Fi card. Check it in ifconfig or iwconfig.

The output is only the "ssid name" of the network you connected...

1
  • 2
    using sudo to get this, especially for a script, is silly.
    – RichieHH
    Jan 6, 2021 at 2:56

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.