Bash Shell Read a Line Field By Field

In Bash shell, you can use the read command to read input line by line, and then use the IFS (Internal Field Separator) variable to specify the delimiter character(s) that separate the fields. Here is an example script that reads input from a file called data.txt and extracts the fields delimited by commas: #!/bin/bash # … Read more

socat: Linux / UNIX TCP Port Forwarder

socat is a powerful and versatile utility that can be used for a wide range of network-related tasks, including TCP port forwarding. To use socat for TCP port forwarding, you can use the following command: $ socat TCP-LISTEN:local_port,fork TCP:remote_host:remote_port In this command, replace local_port with the port number on your local machine that you want … Read more

nginx: Send Custom HTTP Headers

In Nginx, you can send custom HTTP headers to the client by using the add_header directive. Here is an example configuration that adds a custom X-My-Header HTTP header to all responses: server { listen 80; server_name example.com; location / { # Set the content of the custom header add_header X-My-Header “Hello, world!”; # … other … Read more

Linux / UNIX: Convert Epoch Seconds To the Current Time

In Linux/UNIX, you can use the date command to convert epoch seconds to the current time. Here’s an example: #!/bin/bash # Set epoch seconds to a variable epoch_seconds=”1632718301″ # Use the date command to convert epoch seconds to human-readable time formatted_time=$(date -d @$epoch_seconds) echo “Epoch seconds: $epoch_seconds” echo “Formatted time: $formatted_time” In this example, we … Read more

Linux Kernel Recompile: Do I Have To Recompile All Installed Applications

No, you do not have to recompile all installed applications after recompiling the Linux kernel. When you recompile the Linux kernel, you are essentially creating a new kernel image file that contains the new kernel code and configuration options. This new kernel image file is then used when the system boots up. Most user-level applications … Read more

Bash Shell: Trim Leading White Space From Input Variables

In Bash, you can use parameter expansion to trim leading white space from input variables. Here’s an example: #!/bin/bash input=” hello world” trimmed=${input#”${input%%[![:space:]]*}”} echo “Original input: \”$input\”” echo “Trimmed input: \”$trimmed\”” In this example, the input variable is assigned a value with leading white space. The trimmed variable uses parameter expansion to remove the leading … Read more