You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/blog/linux-cmds.md
+173-18
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,12 @@ date = "2023-12-26"
9
9
<!-- General commands -->
10
10
<!-- TODO: grep w/ regex -->
11
11
12
+
## Overview
13
+
14
+
This post serves to document useful Linux commands I use regularly or find useful. I intend to update it periodically as I find more and more useful commands.
15
+
16
+
Some command explanation is included with each, but Linux and command line experience is assumed.
17
+
12
18
## General Commands
13
19
14
20
These commands aren't necessarily Linux machine-specific, but they may come in handy when using one.
@@ -84,6 +90,7 @@ $ kill 921
84
90
85
91
```Bash
86
92
# Run with '-w' to follow in real time (like 'tail -f')
93
+
# The 'journalctl -k' command will also show kernel logs and is generally more flexible
The following assumes an example _system-level_ Systemd unit called `run_periodically.timer`. You can use the same commands for _user-level_ Systemd units like `pulseaudio.service`, e.g. `systemctl status --user pulseaudio.service`.
119
126
127
+
Active (enabled) systemd unit files are located in `/etc/systemd/system/` and `/etc/systemd/user/` directories.
128
+
When modifying systemd units, modify files in these directories. Other unit files exist on Linux systems, primarily in a `/usr/lib/systemd/` directory (depends on distribution). However, generally do not modify these as they are installed by your package manager and are meant as defaults.
The following is a list of `journalctl` commands, each with separate options. Many of these may be combined to perform a specific task. For example, `journalctl -k -b 50 -r` will show the last 50 lines of kernel logs in reverse order (most recent to least recent).
168
+
157
169
Just as Systemd `systemctl` commands support both system-level and user-level units, `journalctl` does as well using the same `--user` argument.
158
170
159
171
```Bash
@@ -164,20 +176,34 @@ $ journalctl
164
176
$ journalctl -n 100
165
177
166
178
# Follow logs in real time (similar to 'tail -f')
179
+
# Can also substitute '--follow' for '-f'
167
180
$ journalctl -f
168
181
182
+
# Show logs in reverse order (most recent to least recent)
183
+
# Cannot use this option with '-f'
184
+
$ journalctl -r
185
+
186
+
# Show all logs that contain the provided pattern, here 'wlan0'
187
+
# Can also substitute the '--grep' option for '-g'
188
+
$ journalctl -g wlan0
189
+
169
190
# Only show logs for a specific ID, here 'test_program'.
170
191
# For example, the following would create a log message and
171
192
# tag it with the 'test_program' tag:
172
-
#logger -t test_program "This is a log message"
193
+
# echo "This is a warning message" | systemd-cat -t test_program -p warning
173
194
#
174
195
# Note that this is different from the '-u' option
175
196
$ journalctl -t test_program
176
197
177
198
# Only show logs for a specific service, here, 'wpa_supplicant.service'
199
+
# Can also provide full Systemd unit name, e.g. here 'wpa_supplicant.service'
178
200
$ journalctl -u wpa_supplicant
179
-
# or
180
-
$ journalctl -u wpa_supplicant.service
201
+
202
+
# Show kernel logs (same output as 'dmesg' command)
203
+
# Can also substitute the '--dmesg' option for '-k'
204
+
#
205
+
# This is the same as 'journalctl -t kernel'
206
+
$ journalctl -k
181
207
182
208
# Only show logs for this boot (can use '-b' option instead of '--boot')
183
209
# When using the '--boot' and '-b' arguments, '0' and '-0' function the same (this boot)
@@ -324,10 +350,11 @@ $ du -h
324
350
You probably want to use Network Manager to configure your networking instead.
325
351
See the [next section](#managing-networking-network-manager) for more details.
326
352
327
-
Most Linux distributions run Network Manager to configure and manage networking nowadays. This is a common point of confusion, as there is still material available online which assumes older, network-scripts based network management.
353
+
Most Linux distributions run Network Manager to configure and manage networking nowadays. This is a common point of confusion, as many guides online reference older, network-scripts based network management and the deprecated `ifconfig` command.
354
+
355
+
It is possible to configure networking with variations of these commands. Generally, though, you'll almost always be better off using a tool like `NetworkManager` or `systemd-networkd`, unless you have a very specific use case.
328
356
329
-
It is possible to configure networking with variations of these commands. Unless you know
330
-
what you're doing, though, you're better off just using Network Manager.
357
+
For more information, see this [very detailed guide](https://axil.gitlab.io/iproute2/).
331
358
332
359
#### Show Network Interface Link-Layer Info</h3>
333
360
@@ -346,7 +373,7 @@ wlan0 UP xx:xx:xx:xx:xx:xx <BROADCAST,MULTICAST,UP,LOWER_
346
373
347
374
#### Show Network Interface IP-Layer Info
348
375
349
-
Displays IPv4 and IPv6 information in addition to interface status, MAC address, MTU, and interface routing table, among other things (some of which require `-d` option). More detailed output is possible by using the `-d` option (without the `-br` option).
376
+
These commands display IPv4 and IPv6 information in addition to other detailed information including interface status, MAC address, MTU, and interface routing table, among other things (some of which require `-d` option). More detailed output is possible by using the `-d` option (without the `-br` option).
350
377
351
378
```Bash
352
379
# Shorthand shown. Full command would be 'ip addr show', but the 'show' is optional.
@@ -526,7 +553,11 @@ $ nmcli c m SSID_NAME \
526
553
527
554
**NOTE:** Most Linux systems use Network Manager to manage and configure networking, including WiFi. See the [Managing Networking](#managing-networking-network-manager) section for more details.
528
555
529
-
#### Show WiFi Interface General Info
556
+
On Linux WiFi interfaces are created using a parent radio device, referred to as 'phys'. These radios come in a variety of form factors, including single radio, single phy and single radio, multi-phy. To view all system phys, run `ls /sys/class/ieee80211/`, which lists all `ieee80211` devices (WiFi phys). Supported interfaces, combinations, and settings depend on the radio firmware and associated Linux device driver. By default, a single WiFi interface is created per phy on system boot in 'managed' mode (WiFi station).
557
+
558
+
While most will be content with `NetworkManager` managing their WiFi interface settings, a more advanced user may find the `wpa_supplicant` and `hostapd` programs of interest. The program `wpa_supplicant` configures WiFi clients, whereas `hostapd` configures WiFi access points (APs, what most people refer to as a router). Both live under the `hostap` project and are widely used, including within tools like `NetworkManager` itself and within commercial APs as well. The configuration syntax is notoriously somewhat difficult, especially if you don't know the details of WiFi well.
559
+
560
+
#### Show WiFi Interface General Information
530
561
531
562
Includes STA MAC, SSID, phy device, channel, frequency, transmit power.
532
563
@@ -548,6 +579,8 @@ Interface wlan0
548
579
549
580
#### Show WiFi Interface Link Information
550
581
582
+
**NOTE:** This command will only show meaningful output when the WiFi interface is connected (associated).
583
+
551
584
Includes AP MAC (if station), SSID, frequency, bandwidth, RSSI (if station), and phy rate (MCS),
552
585
among other things. Phy rate may or may not include NSS.
553
586
@@ -569,7 +602,7 @@ Connected to xx:xx:xx:xx:xx:xx (on wlan0)
569
602
beacon int: 100
570
603
```
571
604
572
-
#### Show WiFi Radio Info
605
+
#### Show WiFi Radio/Phy Info
573
606
574
607
Includes channels and bands in current regulatory domain, ciphers, MCS rates, and antennas, among other things.
575
608
@@ -601,16 +634,138 @@ $ iw phy0 info
601
634
602
635
#### Show Wireless Regulatory Domain Info
603
636
637
+
You may see a combination of 'global' and per-phy regulatory configuration. The following shows both.
638
+
604
639
```Bash
640
+
# Notice the inclusion of sub-1GHz (WiFi HaLow, 802.11ah) and 60GHz (WiGig) spectrum
0 commit comments