⌨️Terminal

WLAN Pi / Linux terminal commands and a few concepts thrown in for good measure.

Lab Objective

Gain experience and confidence using the Terminal to interact with your WLAN Pi.

You do not need to learn these commands, nor do you need to become a wizard with the command line to make good use of your WLAN Pi. But we do want you to become familiar and comfortable executing commands from the terminal.

Basic Cursor Navigation

Use the following shortcuts to quickly move the cursor around the current line while typing a command.

Ctrl+A or Home: Go to the beginning of the line

Ctrl+E or End: Go to the end of the line

Ctrl+xx: Move between the beginning of the line and the current position of the cursor. This allows you to press Ctrl+xx to return to the start of the line, change something, and then press Ctrl+xx to go back to your original cursor position.

To use this shortcut, hold the Ctrl key and tap the X key twice.

Windows:

Ctrl+ <-: Go left (back) one word

Ctrl+ ->: Go right (forward) one word

macOS:

Esc+B / Esc+ <- / Alt+ <- : Go left (back) one word

Esc+F / Esc+ -> / Alt+ -> : Go right (forward) one word

Check operating system version

Check the WLAN Pi OS version and many other stats, internet reachability, current mode, and more.

Let's execute a script created by the WLAN Pi team. A script is a series of commands bundled together into one file. Many tools are just scripts. Scripts can be run with the bash interpreter or other scripting language interpreters such as Python.

Go ahead and try this one:

wlanpi-stats

Unlike Windows, Linux is case sensitive. That means WLPC is different than wlpc, which is different from wLpC. Each of these would represent a different file. If you get a message that says something like "file not found" and you are sure that it does exist, you probably need to check the case.

Common / Useful Linux Commands

Finding where you are with present working directory:

pwd

Checking your login:

whoami

Check the hostname:

hostname

Show the version of Linux you are running:

lsb_release -a

What Linux kernel are we using:

uname -r

View Interface IP Addresses

View all your interfaces and IP addresses

ip address
ip a

View IP address for a specific interface

ip address show eth0
ip a s eth0
ip address show wlan0
ip a s wlan0

View IP neighbor table (ARP cache)

ip neighbor
ip n

View IP routing table

ip route
ip r

View wireless devices

iw dev

View wireless device capabilities

iw list

You'll get a lot of info printed to the terminal. We can send the output to a CLI tool called less which enables interactive reading, allows scrolling and search. View it page by page with less:

iw list | less

Page up/down:

<Space> (down), b (up)

Forward search for a string (press n/ <shift> N to go to next/previous match):

/Frequencies

Exit by pressing q key

Scan

Scan with wlan0 for nearby Wi-Fi networks (if you are not logged in as root, you will need to prefix scan commands with sudo or just sudo !! to run the previous command with sudo)

iw wlan0 scan

View it page by page with less:

iw wlan0 scan | less

There is a lot of information in the scan output. Let's filter it with jc.

jc converts the output of many CLI tools to JSON. It can JSONify the output. We can transform the iw scan output to JSON with jc like so:

jc iw dev wlan0 scan

Wow, OK, we still have a lot of output to sift through to find what we're looking for.

Let's filter it with jq which is a command-line JSON processor and select just a few fields.

jc iw dev wlan0 scan | jq '.[] | .signal_dbm, .bssid, .freq, .ssid'

Great, this is better, but how about we put the fields we care about on the same line?

jc iw dev wlan0 scan | jq -jr '.[] | .signal_dbm, ", ", .bssid, ", ", .freq, ", ", .ssid,"\n"'

How about we sort it?

jc iw dev wlan0 scan | jq -jr '.[] | .signal_dbm, ", ", .bssid, ", ", .freq, ", ", .ssid,"\n"' | sort

Hey, now you've got nifty CLI command to produce a one shot scan of nearby networks!

Want to filter further and only display nearby networks matching on WLAN?

jc iw dev wlan0 scan | jq -jr '.[] | .signal_dbm, ", ", .bssid, ", ", .freq, ", ", .ssid,"\n"' | sort | grep WLAN

Try filtering by something else. Maybe WLPC.

Advanced Commands

Command history

View a list of your previously executed commands with:

history

Re-execute a command from the history, use an exclamation mark followed by x, which represents the desired command list number:

!x

Sudo bang bang

When you enter a command that requires sudo (like reboot), but you forgot! No need to retype the command. Just do this instead:

sudo !!

Tab complete

Complete commands and file paths by starting to type them out, then using the tab key to auto-complete:

hi<tab>

Which becomes:

history

When there are multiple possibilities, double tapping the tab key will list all the possibilities. Try this to see all the wlanpi custom commands:

wlanpi<tab><tab>

wifichannel

wifichannel is a quick reference tool for Wi-Fi channel info lookup, created by Jiri Brejcha.

wifichannel -h

You can quickly:

  • Convert between channel number <--> center frequency

  • List all Wi-Fi channels in a specific band

passwd

You can change your password from the terminal (but only if you want to):

passwd

This is how you can change your password at a later date.

Finding Stuff

Looking for binary files?

whereis iw
whereis python3

Finding binaries in the PATH variable:

which iw
which ip

Examining DNS with dig:

dig thewlpc.com

Monitoring process resources:

htop

Linux Cheat Sheet

If you are hungry for more, here is a cheat sheet with common Linux commands.

Last updated

Was this helpful?