- Posted on
- Featured Image
Questions and Answers
Explore essential Linux Bash questions spanning core scripting concepts, command-line mastery, and system administration. Topics include scripting fundamentals (variables, loops, conditionals), file operations (permissions, redirection, find
/grep
), process management (kill
, nohup
), text manipulation (sed
, awk
), and advanced techniques (error handling, trap
, getopts
). Delve into networking (curl
, ssh
), security best practices, and debugging strategies. Learn to automate tasks, parse JSON/XML, schedule jobs with cron
, and optimize scripts. The list also covers variables expansions (${VAR:-default}
), globbing, pipes, and pitfalls (spaces in filenames, code injection risks). Ideal for developers, sysadmins, and Linux enthusiasts aiming to deepen CLI proficiency, prepare for interviews, or streamline workflows. Organized by complexity, it addresses real-world scenarios like log analysis, resource monitoring, and safe sudo
usage, while clarifying nuances (subshells vs. sourcing, .bashrc
vs. .bash_profile
). Perfect for hands-on learning or reference.
-
This article explains how to use `socat` to establish a TLS tunnel with mutual authentication, ensuring both client and server verify identities. It includes basic `socat` commands, troubleshooting tips, and a detailed mutual authentication setup with SSL certificates and stringent verification, highlighting `socat`'s role in secure network communications.
-
- Posted on
- Featured Image
The blog explains the use of `xxd -r -p` in Linux to convert hexdumps back to binary, primarily focusing on formats without line breaks. A hexdump, frequently used in debugging, displays binary data in hexadecimal format. The `xxd` utility facilitates reversing hexdumps to binary, with `-r` for reversing and `-p` to output without whitespace, helping in data forensics or software development. The guide also includes script examples, installation, and execution steps for practical application. -
- Posted on
- Featured Image
The Linux `pr` command is adept at merging multiple text files side-by-side using the `-m` and `-t` options, which horizontally integrates files while suppressing headers. This functionality, which is not confined to just two files, is useful for varied tasks including report preparation and text formatting, thus enhancing Linux text processing capabilities. -
- Posted on
- Featured Image
The blog post explains how to convert `git log` output into a structured CSV file using `awk` and regular expressions. It covers the initial setup of Git and `awk` on Linux, customizing `git log` output, and detailed `awk` scripting examples for formatting and refining the data, ensuring its integrity in CSV format. The tutorial demonstrates both basic and advanced uses of `awk` for effective data parsing suitable for further analysis or manipulation. -
- Posted on
- Featured Image
The article discusses using the `dd` command to split files into fixed-size chunks in Linux when `split` is unavailable. It explains the importance of specifying the correct byte size, counts, and offsets with `dd` to manage file data accurately in loops for different chunks. Examples of Bash scripts are provided to demonstrate how to split files and extract specific portions efficiently. The piece emphasizes `dd`'s versatility and caution to avoid data loss. -
- Posted on
- Featured Image
This blog explores using `iconv` for transliterating accented characters to ASCII in Linux Bash, focusing on text processing pipelines. `iconv` converts text to various encodings, simplifying tasks like sorting or searching in ASCII-only systems. Examples include transliterating French text in the terminal or via scripts, enhancing text compatibility and handling diversity in characters and languages. -
- Posted on
- Featured Image
This blog highlights how to detect hidden Unicode characters, such as zero-width spaces, in Linux using `grep -P`. Invisible characters can disrupt data processing, often entering text through copying and paste actions. The `grep -P` command supports Perl-compatible regular expressions, which can identify these invisible characters effectively. The article provides examples and scripts to aid users in checking multiple files for these hidden entities, ensuring data integrity and precision in text handling. -
- Posted on
- Featured Image
The article explains the `PROCINFO["sorted_in"]` feature in GNU `awk`, providing users a method to specify array traversal orders, enhancing script flexibility and efficiency. It delves into the mechanics of array sorting by keys or values, with practical examples and applications in sorting sales data, benefiting complex data sorting tasks. -
- Posted on
- Featured Image
This guide shows how to use the `sed` command in Linux Bash to replace text patterns, excluding the Nth occurrence. It gives a detailed command structure and examples, demonstrating `sed`'s functionality for precise text editing, like replacing "apple" with "orange" in a file except for the second occurrence. -
- Posted on
- Featured Image
The article explores the capabilities of `jq` for parsing nested JSON in Bash without whitespace issues. It covers the basics, installation, and practical applications including handling complex structures. The post demonstrates `jq`'s effectiveness through examples and emphasizes its value in Bash scripting for efficient data manipulation. -
- Posted on
- Featured Image
The article introduces the `grep -z` command in Linux, which allows `grep` to process inputs terminated by a NUL character instead of newline, useful for managing filenames with special characters. It explains usage with `find` to handle complex filenames effectively and includes examples and a script demonstration, emphasizing its utility in enhancing scripting and filesystem tasks in Linux. -
- Posted on
- Featured Image
Profiling Bash scripts with `perf stat` helps optimize performance by analyzing CPU and system call usage. Simple to use, developers can prepend `perf stat` to their command, receiving detailed output on CPU cycles, cache hits, and more, aiding in pinpointing inefficiencies and understanding resource use in Linux environments. -
- Posted on
- Featured Image
This article explains how to monitor per-process network usage in Linux using the `/proc/$PID/fd` directory and the `ss` command. It discusses accessing file descriptors and using `ss` to examine socket details, providing a script to automate the process and demonstrating utilization of these built-in tools for detailed insights into individual process interactions with network resources. -
- Posted on
- Featured Image
The blog post explains how to programmatically reattach to a detached tmux session using a script, ideal for developers and system admins. It covers using commands like `tmux list-sessions` and `tmux attach-session -t` within a Bash script to automate session management, enhancing workflow efficiency and reducing manual errors. -
- Posted on
- Featured Image
The article explains using the `timeout` command in Linux for process management, focusing on sending `SIGTERM` followed by `SIGKILL`. It describes `SIGTERM` as a grace period shutdown and `SIGKILL` as a forceful process termination. The command syntax is detailed with examples to demonstrate effective process control, ensuring resources are not consumed unnecessarily by lingering processes. -
- Posted on
- Featured Image
This guide details using the `LD_PRELOAD` environment variable in Linux to temporarily load custom libraries for a single process execution, thereby altering program behavior without global environmental effects. It emphasizes security risks involved and demonstrates with examples how `LD_PRELOAD` can intercept, modify functions, and system calls. -
- Posted on
- Featured Image
The article explores using `mlockall` in Linux to enhance script performance by preventing memory swapping to disk. It details how `mlockall` locks all current and future memory pages into RAM, important in environments like real-time processing where delays are costly. The post discusses permissions, potential system impacts due to high RAM usage, and provides a Bash script example. It emphasizes responsible memory management to prevent system resource issues. -
- Posted on
- Featured Image
The article explains how to use the `flock` command in Linux Bash for implementing mutexes in distributed systems with NFS to prevent data corruption by synchronizing file access. It highlights the importance of ensuring NFS setups support flock effectively and provides scripts to demonstrate mutex implementation using lock files on NFS, emphasizing reliability and network setup. -
- Posted on
- Featured Image
The article delves into the usage of `systemd-run --scope --user` for launching Linux processes within new cgroups, using systemd's management capabilities for precise resource control. It discusses the configuration and benefits of this approach, offering examples that demonstrate how to set individual memory limits for tasks, improving system efficiency and workload management for system administrators. -
- Posted on
- Featured Image
The article explains using `reptyr`, a Linux utility, to reattach detached processes to a new terminal—a helpful solution when a process disconnects from its initiating terminal. Simple to install on various Linux distributions, `reptyr` allows for regaining control of background processes, crucial for effective long-term task management and system administration. It includes installation guides, usage steps, practical examples, and a script to demonstrate how to manage processes efficiently. -
- Posted on
- Featured Image
The blog "Mastering Job Control in Bash with `disown -r`" explores using the `disown` command in Bash, particularly the `-r` option for managing only running jobs. It demonstrates how `disown` detaches processes from the shell, allowing them to continue independently, preventing accidental termination if the shell exits. The article offers usage examples, a demo script, and additional resources for deepening understanding of job control in Bash environments. -
- Posted on
- Featured Image
The article discusses `BASH_ARGV0`, a feature from Bash 5.0 that lets users alter a script's name in process listings. It's useful for system administration, improving security in shared environments, and enhancing monitoring by setting custom or dynamic process names based on script actions. This capability makes it easier to manage and differentiate script instances, offering better control and flexibility in handling script processes. -
- Posted on
- Featured Image
In Bash scripting, `PIPESTATUS` is an array variable that captures exit statuses of commands within a pipeline, offering a detailed check for each component. This feature is crucial for enhanced error handling and robust script execution, ensuring each step of the pipeline functions as intended. -
- Posted on
- Featured Image
In Bash scripting, positional parameters like ``, ``, etc., store input arguments. For accessing the tenth and subsequent parameters, curly braces are used (e.g., ``, ``) to prevent misinterpretation as `0`. This method is necessary for scripts that handle extensive inputs, ensuring parameters are referenced correctly and script functionality is optimized. -
- Posted on
- Featured Image
The article explains how to use the `compgen -v` command in Bash to list shell variables and filter them with regex patterns using `grep`. Examples demonstrate how to find variables starting with 'USER', containing 'path', or ending with '_id'. It includes a Bash script to display variables containing 'USER', enhancing debugging and management of environment variables in scripting tasks.