Telnet: Great for Testing if a TCP Port is Open (and Remote Login)

Telnet is commonly used to check if a TCP connection to a specific port succeeds — essentially testing whether the port is open and reachable. Note that telnet itself is TCP-based, so it cannot test UDP sockets.

Syntax Basic:

telnet [options] host [port]

More complete:

telnet [-8acdEfFKLrx] [-b<host_alias>] [-e<escape_char>] [-k<realm>] [-l<user>] [-n<tracefile>] [-S<tos>] [-X<authtype>] [host [port]]

Quick background Telnet is the classic remote login client based on the TELNET protocol. It lets you run commands on a remote server as if you were sitting in front of it. You log in with username/password, but everything (including credentials) is sent in clear text — very insecure. Most modern Linux servers disable telnet and use SSH instead.

That said, curl can test HTTP services, and telnet can too (more on that below).

For UDP testing, use:

  • nc -u
  • nmap -sU
  • tcpdump
  • Application-level tools like dig for DNS

Common options

  • -4 Force IPv4
  • -6 Force IPv6
  • -8 Allow 8-bit data
  • -a Attempt automatic login (rarely used now)
  • -b<alias> Use alias for host
  • -e<char> Set escape character (default Ctrl+]) Example: telnet -e ^X host port
  • -l<user> Specify login user (for traditional telnet servers) Example: telnet -l root 192.168.1.10
  • -n<file> Log session to file (great for debugging)

In interactive mode After connecting, press Ctrl+] to enter telnet command mode. Useful commands:

  • quit Exit telnet
  • close Close current connection
  • status Show connection status
  • open host port Connect to new host/port
  • set localecho Enable local echo
  • toggle crlf Toggle CR/LF handling

Examples

  1. Connect to a remote telnet service
telnet 192.168.120.206

(or by domain: telnet www.baidu.com)

If it fails:

  • Check IP/address
  • Is the host up?
  • Routing correct? (route)
  • Is telnet service running? (netstat -tlnp → look for TCP 23 LISTEN)
  • Firewall allowing port 23? (iptables -L)
  1. Test TCP reachability (the 80% use case)
telnet 127.0.0.1 6379

Outcomes:

  • Connected → port open and TCP reachable
  • Connection refused → port not listening
  • Connection timed out → network/firewall issue
  1. As a generic TCP client Telnet doesn’t care about application protocols — it just sends whatever you type over TCP. Perfect for quick testing of text-based protocols.

HTTP example:

telnet example.com 80
GET / HTTP/1.1
Host: example.com

(then hit Enter twice)

Redis example:

telnet 127.0.0.1 6379
PING

→ +PONG

Typical telnet service config (/etc/xinetd.d/telnet)

service telnet
{
    disable = no
    flags = REUSE
    socket_type = stream
    wait = no
    user = root
    server = /usr/sbin/in.telnetd
    log_on_failure += USERID
}

Restrict access:

only_from = 10.0.0.2
no_access = 10.0.0.{2,3,4}
access_times = 9:00-12:00 13:00-17:00
bind = 10.0.0.2

Limitations

  • Clear-text transmission of credentials → never use for real logins in production (use SSH)
  • Can’t test UDP
  • Binary protocols will garble output → stick to text protocols

Modern role: Telnet is best positioned as a quick TCP port/text-protocol debugging tool, not a login method.

Related tools

  • nc/netcat → Swiss army knife for TCP/UDP
  • curl → HTTP/HTTPS testing
  • ssh → Secure remote login
  • nmap → Port scanning (including UDP)

Telnet Man Page Lists “The source code is not comprehensible” as a BUG

Here’s the man page for the telnet command in an old Ubuntu release:

http://manpages.ubuntu.com/manpages/karmic/man1/telnet-ssl.1.html

Scroll all the way to the bottom and you’ll find this under BUGS:

The source code is not comprehensible.

The source package is here: http://packages.ubuntu.com/source/dapper/netkit-telnet

Download it and take a look — it’s genuinely hard to read. A quick scan reveals at least these issues:

  1. Indentation mixes spaces and tabs, so large parts of the code appear completely unindented.
  2. Heavy use of #if/#else and a ton of preprocessor macros, including some odd ones like:
#ifndef B19200
#define B19200 B9600
#endif
#ifndef B38400
#define B38400 B19200
#endif
  1. What looks like C++ written in C — there are actual class declarations in terminal.cc.
  2. Variable names are cryptic (lots of old, tmp, c1, c2, s1, s2, s3), function naming is inconsistent, and there’s basically no coding style guide.

It’s legitimately tough to follow.

Still, huge respect to whoever decided to call out the source code’s readability as an official BUG in the man page.

(via coolshell.cn)

ip Command: Manage IP Addresses, Network Devices, Routing Tables, and Network Namespaces

Overview

The ip command in Linux is a powerful utility for managing IP addresses, network interfaces, routing tables, and network namespaces. It provides granular control over various network configurations, making it an essential tool for system administrators.

Syntax

ip addr add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]
ip route list|flush|add|del|change|append|replace|test ROUTE
ip link set IFACE [up|down] [arp on|off] [multicast on|off] \
        [promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC] \
        [master IFACE | nomaster] [netns PID]
ip tunnel add|change|del|show [NAME] \
        [mode ipip|gre|sit] [remote ADDR] [local ADDR] [ttl TTL]
ip neigh show|flush [to PREFIX] [dev DEV] [nud STATE]
ip rule [list] | add|del SELECTOR ACTION

Key Features and Examples

Manage IP Addresses

View IP addresses:

ip addr

Add an IP address to a device:

ip addr add 192.168.1.1/24 dev eth0

Remove an IP address:

ip addr del 192.168.1.1/24 dev eth0

Flush all IP addresses for a device:

ip addr flush dev eth0

Manage Network Devices

Display all network interfaces:

ip link

Show specific device details:

ip link show dev eth0

Bring an interface up or down:

ip link set eth0 up
ip link set eth0 down

Set MTU for a device:

ip link set eth0 mtu 1450

Add or delete a bridge device:

ip link add br0 type bridge
ip link del br0

Create a virtual Ethernet pair:

ip link add veth0 type veth peer name veth1

Manage Routing Tables

Display the main routing table:

ip route show table main

Add a default route:

ip route add default via 10.8.1.1 dev eth0

Add a static route:

ip route add 10.8.1.0/24 via 10.8.1.1

Replace an existing route:

ip route replace 10.8.1.0/24 dev eth0

Flush the routing table:

ip route flush cache

Manage Routing Rules

Show routing rules:

ip rule

Add a rule to use a specific table:

ip rule add from 10.8.1.0/24 table 520

Blackhole traffic from a specific source:

ip rule add from 0/0 blackhole

Manage Network Namespaces
List network namespaces:

ip netns

Create a network namespace:

ip netns add s1

Delete a namespace:

ip netns del s1

Execute a command within a namespace:

ip netns exec s1 ip addr

Example: Setting MTU

MTU (Maximum Transmission Unit) defines the maximum packet size for data transmission on a network device. Adjusting MTU impacts performance and compatibility.

View the current MTU for eth0:

ip link show eth0

Set MTU to 1450 bytes:

ip link set eth0 mtu 1450

Common MTU Values:

  • Ethernet: 1500 bytes (default)
  • PPPoE: 1492 bytes (8 bytes for headers)
  • Wi-Fi: Often 1500 bytes but can vary slightly.

Quick Tips with ip

Color-coded output:

ip -c addr
ip -c route

Compact display:

ip -brief link
ip -brief addr

For detailed configuration guides, check the official documentation.

newgrp: Changing the Current User’s Group

Overview:
newgrp is a command used to change the group associated with the current user. It allows the user to switch to a different group, affecting file permissions and other operations. This command operates within the context of the currently logged-in user, meaning it cannot be used to change the group for other users.

Syntax:

newgrp [group_name]

Details:
newgrp works similarly to the login command. It allows the user to log in again under the same account but with a different group. The primary effect of running newgrp is that it switches the user’s effective group to the specified one, which will influence operations such as file access permissions.
If no group is specified, newgrp logs the user into the default group associated with the user’s username.
To use newgrp to switch groups, the user must be a member of the specified group. Otherwise, access to that group will be denied. Once a user has switched groups via newgrp, they can revert to their original group by using the exit command to close the current shell session.

Parameters:

  • group_name: The name of the group to switch to.

Example:
To add a user to the docker group:

$ sudo usermod -aG docker username

Replace username with the actual username. To add the current user to the docker group, run:

$ sudo usermod -aG docker $USER

After adding the user to the docker group, a re-login or system restart is required for the changes to take effect. Alternatively, use the following command to reload the user’s group memberships without logging out:

$ newgrp docker

jq: Command-line Tool for Handling JSON Data

Overview
jq is a command-line utility for processing JSON data, similar in functionality to sed and awk but specifically designed for JSON, making it extremely powerful for parsing, filtering, and formatting JSON data.

Usage

jq [options] <jq filter> [file...]
jq [options] --args <jq filter> [strings...]
jq [options] --jsonargs <jq filter> [JSON_TEXTS...]

Description
jq processes JSON input by applying specified filters to JSON text, outputting the result in JSON format to standard output. The simplest filter is . (dot), which outputs the JSON input as-is (with formatting adjustments and IEEE 754 numeric representation). For more complex filters, refer to the jq(1) manual or jq’s official documentation.

Options

  • -c: Compresses output, removing whitespace and newlines to produce compact JSON.
  • -r: Outputs raw format without quotes, useful for string values.
  • -R: Reads raw strings instead of JSON text.
  • -s: Slurps all input JSON objects into a single array.
  • -n: Uses null as the input, often used to create new JSON objects without reading input.
  • -e: Sets exit status based on output.
  • -S: Sorts keys in output JSON objects.
  • -C: Colors JSON output (enabled by default).
  • -M: Monochrome mode, disables JSON coloring.
  • --tab: Indents using tabs.
  • --arg a v: Sets $a to value <v>.
  • --argjson a v: Sets shell variable $a to JSON value <v>.
  • --slurpfile a f: Sets $a as an array from JSON data in file <f>.
  • --rawfile a f: Sets $a to the raw content of file <f>.
  • --args: Treats remaining arguments as string parameters, not files.
  • --jsonargs: Treats remaining arguments as JSON parameters.
  • --: Stops processing options.

Arguments can also be accessed using $ARGS.named[] for named parameters or $ARGS.positional[] for positional parameters.

Parameters

  • file...: One or more files.
  • strings...: One or more strings.
  • JSON_TEXTS...: One or more JSON strings.

Filters

  • .: Refers to the current JSON object, used to access fields.
  • []: Accesses elements in an array.
  • |: Passes output from one expression as input to the next.
  • {}: Creates a new JSON object.
  • [] | .field: Traverses an array and extracts specific fields from each object.

Operators and Built-in Functions
Includes common operators (+, -, *, /, %) and functions like length, has, map, select, unique, min, and max. String functions include split, join, startswith, and endswith. Regex and mathematical functions are also available, such as test, match, sqrt, and range.

Examples

1 Basic Examples

Compact JSON output by removing whitespace and newlines:

echo '{"name": "Alice", "age": 30}' | jq -c .

Output:
{"name":"Alice","age":30}

Raw output without quotes, typically for string values:

echo '{"name": "Alice", "age": 30}' | jq -r .name

Output:
Alice

Combine all input JSON objects into an array:

$ echo '{"name": "Alice", "age": 30}{"name": "Bob", "age": 25}{"name": "Charlie", "age": 35}' | jq -s .

Output:

[
  { "name": "Alice", "age": 30 },
  { "name": "Bob", "age": 25 },
  { "name": "Charlie", "age": 35 }
]

Passing shell variables to jq as JSON variables:

name="Alice"
echo '{}' | jq --arg name "$name" '{name: $name}'

Output:
{ "name": "Alice" }

2 Filter Examples

Access an element in a JSON array:

echo '[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}]' | jq '.[1]'

Output:

{ "name": "Bob" }

Create a new JSON object with defined key-value pairs:

jq -n '{name: "Alice", age: 30}'

Output:

{ "name": "Alice", "age": 30 }

Traverse an array and extract a specific field from each object:

echo '[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}]' | jq '.[].name'

Output:

"Alice"
"Bob"
"Charlie"

3 Operators, Control Statements, and Built-in Functions

Use conditional expressions to modify output:

echo '[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}, {"name": "Charlie", "age": 35}]' | jq 'map(if .name=="Alice" then "yes" else "no" end)'

Output:

[ "yes", "no", "no" ]

4 jq Scripts

Save complex jq commands in a .jq file and execute them:

Create a file script.jq with:

map(select(.age > 28) | {name: .name, status: (if .age < 35 then "young" else "mature" end)})

Run the script:

echo '[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}, {"name": "Charlie", "age": 35}]' | jq -f script.jq

Output:

[
  { "name": "Alice", "status": "young" },
  { "name": "Charlie", "status": "mature" }
]

Alternatively, save JSON data to a file and filter it:

$ echo '[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}, {"name": "Charlie", "age": 35}]'>input.json
$ jq -f script.jq input.json

Output:

[
  { "name": "Alice", "status": "young" },
  { "name": "Charlie", "status": "mature" }
]

echo: Printing Strings or Variables in Terminal

Overview
The echo command is used to display strings or variables in the terminal.

Usage

echo [options] [args]

Description
echo is ideal for outputting text, displaying variables, and creating formatted outputs.

Options

  • -e: Enables escape characters such as newline \n and tab \t. Common escape sequences include:
    • \n: Newline
    • \t: Horizontal tab
    • \\: Backslash
    • \": Double quote
    • \a: Alert (beep)
    • \b: Backspace
    • \v: Vertical tab
  • -n: Prevents auto newline at the end of the output. By default, echo will automatically add a newline, which -n can disable.

Arguments

  • args: One or more strings or variables to be printed.

Examples

1 Simple Text Output

$ echo "Hello, World!"

Output:
Hello, World!

2 Display Variable Values
You can print variable values by prefixing the variable name with $:

$ name="Alice"
$ echo "Hello, $name"

Output:
Hello, Alice

To display environment variables:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

$ echo $HOME
/home/user

$ echo $USER
user

3 Using Command Substitution
echo can use command substitution with $(command) to insert the output of a command:

$ echo "Today is $(date)"

Output:
Today is Sun Oct 25 10:20:22 AM

4 Multi-line Output
Use the -e option to enable escape characters like \n for multi-line output:

$ echo -e "Line 1\nLine 2\nLine 3"

Output:

Line 1
Line 2
Line 3

5 Suppress Auto Newline
To suppress the newline, use -n:

$ echo -n "Hello, World!"

Output:
Hello, World! (without newline)

6 Using Escape Characters
Enable escape characters with -e for features like tabs (\t) and newlines (\n):

$ echo -e "Column1\tColumn2\nData1\tData2"

Output:

Column1    Column2
Data1      Data2

7 Redirect Output to File
Redirect echo output to a file. Use > to overwrite or >> to append:

$ echo "Hello, World!" > output.txt    # Overwrite
$ echo "Another Line" >> output.txt     # Append

8 Output Strings with Special Characters
For special characters (like $, “, ), use single quotes or escape them with \:

$ echo "This is a dollar sign: \$ and a quote: \""

Output:
This is a dollar sign: $ and a quote: “

Monitoring CIFS File System I/O Performance with cifsiostat

Description: cifsiostat is a tool used to monitor the I/O performance of CIFS file systems.

Syntax:

cifsiostat [ options ] [ <interval> [ <count> ] ] [ mount point ]

Overview: cifsiostat is a tool for monitoring I/O performance of CIFS (Common Internet File System) file systems, similar to iostat. It is part of the sysstat package and is specifically designed to display I/O statistics for CIFS client mount points. CIFS is a network file-sharing protocol based on SMB (Server Message Block), commonly used in Windows environments but also supported by Linux and other operating systems.

Options:

  • -k Show I/O activity statistics in kilobytes per second instead of blocks per second.
  • -m Show I/O activity statistics in megabytes per second.

Parameters:

  • Interval The time interval (in seconds) between each output.
  • Count The total number of outputs.
  • Mount Point Show I/O activity statistics for a specific mount point.

Examples:

1 Display I/O activity statistics for all CIFS mount points:

    cifsiostat

    2 Output statistics every 5 seconds for a total of 10 times:

    cifsiostat 5 10

    3 Show statistics for a specific mount point:

    cifsiostat /mnt/cifs

    4 View I/O statistics for two mount points:

    cifsiostat /mnt/shared /mnt/backup

    The output of cifsiostat is similar to iostat, including the number of read and write operations, the amount of data read and written, the average I/O size, and I/O wait times. An example output is shown below:

    Example Output:

    Filesystem: /mnt/cifs
    rMB/s    wMB/s    rIO/s    wIO/s   rSizeKB   wSizeKB
    0.000    0.012    1.00     10.00   0.00      4.00

    Explanation of Fields:

    rMB/s MB read per second.
    wMB/s MB written per second.
    rIO/s Number of read I/O requests per second.
    wIO/s Number of write I/O requests per second.
    rSizeKB Average size (in KB) of each read operation.
    wSizeKB Average size (in KB) of each write operation.

    NFS I/O Monitoring with nfsiostat: A Quick Guide

    The nfsiostat command is a tool for displaying I/O statistics for each NFS (Network File System) mount point on the client. Similar to iostat, it helps monitor NFS performance by providing real-time data on the I/O activities of mounted NFS points.

    Usage

    nfsiostat [ interval [ count ] ] [ options ] [ <mount point> ]

    Installation

    On Ubuntu, you can install nfsiostat by running the following command:

    sudo apt install nfs-common

    Key Options

    • -a, --attr: Displays statistics related to the attribute cache.
    • -d, --dir: Displays statistics related to directory operations.
    • -p, --page: Displays statistics related to the page cache.
    • -s, --sort: Sorts NFS mount points by operations per second (ops/second), useful for identifying the most active I/O points.
    • -l LIST, --list=LIST: Only displays statistics for the first LIST number of mount points, allowing a focused view of key NFS points.

    Parameters

    • interval: Sets the time interval (in seconds) between reports. The command will keep running until manually stopped or until the specified count of reports is reached.
    • count: Specifies the total number of reports to generate before terminating.
    • mount point: The NFS mount point(s) to monitor. You can specify one or more mount points to view detailed statistics for specific NFS mounts instead of all mounted NFS points by default.

    Examples

    • Report I/O statistics every 5 seconds, for a total of 10 times:
    nfsiostat 5 10

    Identify which mount points have the highest I/O activity:

    nfsiostat -s

    Print statistics for the first 2 mount points:

    nfsiostat -l 2

    View I/O statistics for the /mnt/nfs mount point:

    nfsiostat /mnt/nfs

    This tool provides a valuable way to monitor the performance of NFS mounts in real time, helping system administrators identify potential bottlenecks and optimize their NFS configurations.

    Monitoring System Resources with pidstat: CPU, Memory, Threads, and Device I/O Usage

    pidstat is a versatile command-line tool designed to monitor system resource usage, including CPU, memory, threads, and device I/O, across all or selected processes.

    Overview:

    pidstat is used to monitor the usage of CPU, memory, threads, device I/O, and other system resources for all or specific processes.

    Syntax:

    pidstat [options] [<interval> [<count>]]

    Description:

    When pidstat runs for the first time, it displays statistics from system startup. Subsequent executions will show data since the last run. Users can specify the interval and the number of times statistics should be displayed. It is part of the sysstat package, a performance monitoring toolkit, and can be accessed after installing sysstat.

    Options:

    • -u – Display CPU usage of each process.
    • -r – Display memory usage of each process.
    • -d – Display I/O usage of each process.
    • -p <pid> – Specify process ID to monitor.
    • -w – Display context switch details for each process.
    • -t – Show additional thread statistics.
    • -V – Display the version of the tool.
    • -h – Display header in a more compact format to fit narrower terminal windows.
    • -I – On SMP systems, displays CPU usage per core.
    • -l – Show command name and all parameters.
    • -T {TASK | CHILD | ALL} – Scope of reported statistics:
      • TASK: Report stats for the specified task (process).
      • CHILD: Report stats only for child processes, useful for performance monitoring of a process’s descendants.
      • ALL: Comprehensive stats for both the task and all its child processes.
    • -C <command> – Monitor the status of processes associated with a specific command.

    Parameters:

    • interval: Time between displays (in seconds).
    • count: Number of times to display, default is continuous.

    Example Usage:

    Basic Usage:

    $ pidstat

    Example output:

    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)   2024-10-19   _x86_64_   (2 CPU)
    
    Time       UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
    16:03:44   0         1      0.00    0.00    0.00    0.00    0.00     0  systemd
    16:03:44   0         2      0.00    0.00    0.00    0.00    0.00     0  kthreadd
    16:03:44   0        16      0.00    0.00    0.00    0.00    0.00     0  ksoftirqd/0

    Display CPU Usage for All Processes:

    $ pidstat -u -p ALL

    Example output:

    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)   2024-10-19   _x86_64_   (2 CPU)
    
    Time       UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
    16:17:49   0         1      0.00    0.00    0.00    0.00    0.00     0  systemd
    16:17:49   0         2      0.00    0.00    0.00    0.00    0.00     0  kthreadd

    Display CPU Usage for a Specific Process:

    $ pidstat -u -p 1

    Example output:

    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)   2024-10-19   _x86_64_   (2 CPU)
    
    Time       UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
    16:18:07   0         1      0.00    0.00    0.00    0.00    0.00     1  systemd

    Display I/O Usage:

    $ pidstat -d

    Example output:

    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)   2024-10-19   _x86_64_   (2 CPU)
    
    Time       UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
    16:26:23   1000      1606    0.23      0.02      0.02       0  systemd

    Display Context Switches:

    $ pidstat -w

    Example output:

    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)   2024-10-19   _x86_64_   (2 CPU)
    
    Time       UID       PID   cswch/s nvcswch/s  Command
    16:29:11   0         1     0.19      0.04  systemd

    Display Thread Statistics:

    $ pidstat -t

    Example output:

    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)   2024-10-19   _x86_64_   (2 CPU)
    
    Time       UID      TGID       TID    %usr %system  %guest   %wait    %CPU   CPU  Command
    16:31:15   0         1         -    0.00    0.00    0.00    0.00    0.00     0  systemd

    Field Explanations:

    • PID: Process ID
    • %usr: CPU percentage used in user space
    • %system: CPU percentage used in kernel space
    • %guest: CPU percentage used in virtual machine
    • %CPU: Total CPU percentage used by the process
    • CPU: CPU core number
    • Command: Command associated with the process

    pidstat provides an in-depth look at resource usage, helping users understand how individual processes consume system resources, making it invaluable for performance monitoring and troubleshooting.

    iostat: A Tool for Monitoring System I/O Statistics

    Functionality:
    iostat is a utility used to gather and report system I/O statistics, commonly employed for analyzing disk performance.

    Syntax:
    iostat [options]

    Overview:
    In addition to I/O statistics, iostat can also display CPU usage information.

    Common Options:

    • -c: Display CPU usage only.
    • -d: Show device utilization statistics only.
    • -k: Display statistics in kilobytes per second instead of blocks per second.
    • -m: Display statistics in megabytes per second.
    • -p: Display statistics for block devices and all utilized partitions.
    • -t: Display the time each report is generated.
    • -V: Display version information and exit.
    • -x: Display extended I/O statistics.

    Examples:

    To display the usage of all devices at the current time:

    $ iostat -x
    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)  2024年10月18日  _x86_64_  (2 CPU)
    
    avg-cpu:  %user  %nice  %system  %iowait  %steal  %idle
               0.10   0.02    0.27     0.01    0.00   99.60
    
    Device      r/s  rkB/s  rrqm/s  %rrqm  r_await  rareq-sz  w/s  wkB/s  wrqm/s  %wrqm  w_await  wareq-sz  %util
    loop0      0.00   0.00    0.00   0.00    0.00     1.21   0.00    0.00   0.00   0.00    0.00     0.00    0.00
    ...
    sda        0.30  10.96    0.10  24.42    0.35    36.60   0.51   23.23   0.64  55.59    0.41    45.13    0.02

    Field Descriptions:

    • Device: Device name.
    • r/s: Number of read requests per second.
    • w/s: Number of write requests per second.
    • rkB/s: Kilobytes read per second.
    • wkB/s: Kilobytes written per second.
    • %util: Percentage of time the device was busy with I/O requests.

    To display statistics for the device sda:

    $ iostat -x /dev/sda
    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)  2024年10月18日  _x86_64_  (2 CPU)
    
    avg-cpu:  %user  %nice  %system  %iowait  %steal  %idle
               0.10   0.02    0.27     0.01    0.00   99.60
    
    Device      r/s  rkB/s  rrqm/s  %rrqm  r_await  rareq-sz  w/s  wkB/s  wrqm/s  %wrqm  w_await  wareq-sz  %util
    sda        0.30  10.95    0.10  24.42    0.35    36.60   0.51   23.21   0.64  55.57    0.41    45.09    0.02

    To display only device usage without CPU statistics:

    $ iostat -xd /dev/sda

    For overall system I/O status:

    $ iostat
    Linux 6.8.0-45-generic (Ubuntu22-VirtualBox)  2024年10月18日  _x86_64_  (2 CPU)
    
    avg-cpu:  %user  %nice  %system  %iowait  %steal  %idle
               0.10   0.02    0.27     0.01    0.00   99.60
    
    Device     tps  kB_read/s  kB_wrtn/s  kB_dscd/s  kB_read  kB_wrtn  kB_dscd
    loop0      0.00      0.00      0.00      0.00        17        0        0
    ...
    sda        0.81     10.95     23.21      0.00   4791860  10157237       0

    To display CPU I/O statistics only:

    $ iostat -c

    To display statistics in megabytes per second:

    $ iostat -m