- 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.
-
The article explains side effects in Bash arithmetic expressions, particularly how pre-increment (`++i`) and post-increment (`i++`) operators affect a variable's value and the outcome of expressions. It highlights the importance of understanding these effects for efficient script writing in Bash, offering a detailed example and a script to demonstrate these concepts in action.
-
- Posted on
- Featured Image
In Bash scripting, memory allocation plays a crucial role in script performance and reliability. Normally, Bash uses `mmap()` for large memory blocks, but it can be configured to use `malloc()`, which helps reduce virtual memory fragmentation and may enhance performance on some systems. Setting the `MALLOC_MMAP_THRESHOLD_` environment variable to 0 directs `malloc()` to never utilize `mmap()` for memory allocation. This adjustment is demonstrated through a sample script that showcases memory allocation in varied operations. -
- Posted on
- Featured Image
The article delves into advanced Bash debugging with `shopt -s extdebug` and `declare -ft`, tools that enhance script debugging by enabling detailed function tracing and execution flow tracking. It includes practical examples showing how these tools help in troubleshooting and improving script performance, making them indispensable for Bash developers. -
- Posted on
- Featured Image
This article explains how to override the PATH lookup in Linux with `env -i /absolute/path/to/bin`, detailing benefits such as enhanced security, consistency, and debugging. Using `env -i` allows the execution of a command with a clean environment, bypassing the PATH variable to eliminate risks of executing incorrect versions of a command, proving vital in complex system setups with multiple software versions. -
- Posted on
- Featured Image
The blog discusses two methods to temporarily disable alias expansion in Linux Bash—using the `command` utility or a backslash (`\`). This is vital for script reliability and troubleshooting, ensuring commands execute as intended without interference from user-defined aliases. Examples show how to override aliases for commands like `rm` to prevent unpredictable outcomes. -
- Posted on
- Featured Image
This blog details the use of the `BASH_COMMAND` in a `trap` command for logging exact Bash script executions, enhancing debugging and script robustness. It explains `trap` functionality, incorporates `BASH_COMMAND` for monitoring script behaviors during triggers, and provides practical examples, including logging executed commands upon script exit or during interruptions, boosting script reliability and maintenance. -
- Posted on
- Featured Image
The article details the usage of `ionice`, a Linux command for managing I/O scheduling priorities to optimize application performance during significant disk access. By assigning specific priorities and classes to processes, `ionice` helps prioritize urgent tasks on servers and multi-user systems, ensuring system responsiveness. Practical examples, including a test script, demonstrate how to apply `ionice` for different tasks, such as database queries and background backups. -
- Posted on
- Featured Image
This blog post demonstrates how to establish a RAM disk on Linux with `tmpfs`, which uses RAM for high-speed temporary file storage, deleting data upon reboot. It explains a non-interactive setup, detailing a Bash script for creating a 1GB RAM disk at `/mnt/ramdisk`, facilitating automated tasks or system setups. -
- Posted on
- Featured Image
The article describes the use of `ebtables` to filter ARP traffic, focusing on its implementation in a Bash script for network security enhancement. It explains common `ebtables` commands for managing ARP packets and provides a detailed Bash script example to log ARP requests and replies. This helps in monitoring ARP traffic and preventing issues like ARP spoofing. -
- Posted on
- Featured Image
The article explores `ps_mem.py`, a Python script for monitoring memory usage of processes on Linux. It accurately allocates shared memory among processes and offers a clear view of individual memory consumption. Offering a comprehensive guide, the article demonstrates installing the tool using wget or curl and setting up a custom script to monitor processes by PID periodically, thus aiding in efficient system management. -
- Posted on
- Featured Image
The article explains how to use the `taskset` command in Linux to assign a script to a specific CPU core, enhancing performance by optimizing CPU affinity. This technique helps in reducing cache misses and is especially beneficial for performance-critical tasks in multi-core systems. Examples and a practical guide are provided to effectively manage system workload and optimize execution. -
- Posted on
- Featured Image
The blog article describes how to use `LD_DEBUG=files` for tracking shared library dependencies in bash scripts on Linux systems. This feature aids in debugging, optimizing, and securing applications by providing detailed outputs on libraries loaded during program execution. It includes a beginner-friendly example with the `ls` command and an advanced example involving a C program compilation to demonstrate practical applications. -
- Posted on
- Featured Image
Learn how to dynamically change the scheduling priority of Linux processes using the `chrt` command. Essential for system administrators, this technique optimizes system responsiveness by adjusting CPU time allocation among tasks. The article explains how to implement real-time policies (`SCHED_OTHER`, `SCHED_FIFO`, `SCHED_RR`) and manage process priorities effectively. -
- Posted on
- Featured Image
This article explores managing Linux kernel modules using commands `modprobe` for loading modules with dependencies, and `rmmod` for unloading them without dependency management. Tools like `lsmod` are also discussed for tracking active modules. Practical examples and a script for automating tasks, such as managing the `vboxdrv` module, are provided, underscoring their utility for system administrators and developers. -
- Posted on
- Featured Image
This article explores how to use `sysctl -w` for modifying Linux kernel parameters, focusing on network settings such as IPv6 and ICMP responses. It covers practical uses, such as disabling or enabling IPv6 across all interfaces and managing ICMP echo requests, providing executable script examples to illustrate changes. Essential for system administrators, `sysctl` offers a powerful tool for optimizing system performance and security. -
- Posted on
- Featured Image
The blog article provides guidance on optimizing Linux system performance by adjusting the `vm.swappiness` parameter, which defines the kernel's preference for swapping memory pages versus retaining them in physical memory. Tuning this setting can enhance system stability and performance, especially under varying workloads. The article also introduces a script to dynamically adjust `vm.swappiness` based on system load, offering a practical approach to resource optimization. -
- Posted on
- Featured Image
Learn how to automate network reconnaissance using the `nmap` Scripting Engine (NSE) alongside Bash. NSE enables the creation of scripts for automated checks and vulnerability detection, which can be incorporated into Bash to enhance efficiency, manage regular network audits, and bolster security protocols. -
- Posted on
- Featured Image
This blog article explains using the `curl` command-line tool to bypass proxy settings with the `--socks5-hostname` option. This approach directs requests through a SOCKS5 proxy, resolving hostnames at the proxy, unlike `--socks5` which resolves locally. Useful for avoiding restrictive proxies or testing server connections directly, it enhances control without altering global settings. An example and script demonstrate this method's application. -
- Posted on
- Featured Image
-
- Posted on
- Featured Image
This article explores the `firejail` sandboxing tool which enhances Linux security by restricting script syscalls using Linux namespaces and seccomp technology. It explains how restricted syscalls either kill the process or fail, illustrating with a script limited to benign system calls and demonstrating syscall blocking in action. -
- Posted on
- Featured Image
The article details how to use `bash` scripts for real-time monitoring of `sudo` command usage by parsing the `/var/log/secure` file on Linux. It highlights the use of `tail` and `awk` to dynamically track and respond to `sudo` invocations, enhancing security and user accountability. A sample script is provided to demonstrate instant notification of `sudo` activities. -
- Posted on
- Featured Image
The article explains how to securely erase files in Linux using `shred -u`, which overwrites files multiple times, truncates, and deletes them, making the data difficult to recover. It details using `shred -u -n 10 -z filename` for effective deletion, and demonstrates how to verify this deletion by checking inode changes with the `stat` command. Limitations on certain file systems are also discussed. -
- Posted on
- Featured Image
The article discusses the use of `ssh-keygen -Y` in Bash 8+ for signing and verifying files using SSH keys, a vital function for maintaining data integrity and authentication in environments like software development. It explains how to sign files with a private SSH key and verify them using the corresponding public key, providing commands and a practical Bash script example to implement these security measures effectively. -
- Posted on
- Featured Image
Discover how to create a basic port scanner using Linux's `/dev/tcp` and the `timeout` command in this blog post. The `/dev/tcp` pseudo-device facilitates direct TCP socket interactions from the Bash shell, enabling users to assess port availability. The post showcases how to manage connection timeouts with the `timeout` command to make scanning efficient and provides a script that demonstrates detecting open ports on specified host and port range. -
- Posted on
- Featured Image
This article details how to generate a Time-based One-Time Password (TOTP) token using Bash, `openssl`, and `date +%s`. It clarifies TOTP's role in two-factor authentication by combining a secret key and the current time to produce a constantly updating password. Step-by-step, the article demonstrates creating a TOTP token with a Bash script and accentuates the importance of secure key management.