linux

All posts tagged linux by Linux Bash
  • 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 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 explores using `SIGRTMIN+1` for inter-process communication in bash scripts, a real-time signal in Linux ideal for high-priority communications. It details setting up a bash trap for the signal, ranging from 34 to 64, and provides an example script demonstrating how to define a handler function and check for the signal continuously. The article emphasizes the simplicity and efficiency of this method over other IPC techniques.
  • Posted on
    Featured Image
    This blog post highlights using `kill -l` in bash scripts for dynamic signal mapping, improving script flexibility and maintainability. The `kill` command in Linux sends signals to processes, such as `SIGTERM` and `SIGKILL`. `kill -l` lists signals with their numbers, enhancing script readability. The post demonstrates this concept through a script example that requires users to select a signal for a specified PID, dynamically obtaining the signal number via `kill -l`. This approach serves both novice and experienced Linux users.
  • Posted on
    Featured Image
    The blog article describes how to use the `tee` command along with FIFOs (First In, First Out pipelines) in Linux for splitting a single data stream into multiple processes. This method enhances concurrent real-time data processing by utilizing named pipes created with `mkfifo`, allowing output from one source to efficiently feed into various processes concurrently without disk storage. Example configurations demonstrate the practical application of these techniques in logging and data analysis.
  • Posted on
    Featured Image
    The article discusses how to work safely with raw disk devices like `/dev/sda` in Linux. It emphasizes the importance of using commands such as `lsblk` and `fdisk -l` to correctly identify devices, ensuring that no mounted filesystems are involved before writing. It also provides a script that includes several safety checks and requires root access, which uses `dd` for data writing and offers progress status. The guide is aimed at preventing data corruption and loss by advocating for strict verification and backup procedures.
  • Posted on
    Featured Image
    The blog article discusses the `dd` command in Linux, specifically highlighting the use of `conv=notrunc` to modify sections of a file without erasing its entirety. It details practical applications such as updating text in a file while preserving the rest of the data and emphasizes how `dd` is crucial for managing large datasets and precision file alterations.
  • Posted on
    Featured Image
    The article explains how to convert `sar` output into a CSV format on Linux systems to facilitate better trend analysis. The `sar` command is part of the sysstat package and captures key system performance metrics. By using CSV format, the data becomes easily manageable with tools like Excel or Python, enhancing data manipulation and visualization capabilities. The conversion process is detailed with a bash script example for effective transformation, making trend analysis more accessible for performance tuning and making informed decisions.
  • Posted on
    Featured Image
    The article provides a thorough guide on adjusting `ulimit` values in Linux to effectively manage system resources. It explains the importance of `ulimit` for regulating resources in shell processes, particularly for scripts' child processes, to maintain system stability and avoid resource hogging. It includes steps for setting `ulimit` values in bash scripts and demonstrates with examples how to apply these limits to processes such as the number of open files and user processes.
  • Posted on
    Featured Image
    The blog post details using `sysdig` to trace file accesses in Linux, highlighting its capability to capture system events directly from the kernel. It offers installation instructions for different Linux distributions and uses a command format with specified filters to monitor file accesses by scripts. Practical examples, including a Bash script, demonstrate `sysdig`'s utility in debugging, security, and system performance optimization.
  • Posted on
    Featured Image
    Explore the `logrotate` tool in Linux to effectively manage log files without needing to restart services. This utility automates the rotation, compression, and removal of log files, ensuring uninterrupted server operation and efficient log handling. Learn about its setup through example configurations and scripts that illustrate daily log rotation and service reloading, demonstrating `logrotate`'s ability to prevent service disruption and data loss.
  • Posted on
    Featured Image
    The article discusses using the `auditd` service to monitor user command history in Linux for enhanced security and compliance. It details how `auditd` captures system calls and commands, providing audit trails crucial for forensic purposes. It describes setting up rules to log all user commands and provides examples for specific users and commands, including script demonstrations for implementing and reviewing `auditd` logs.
  • Posted on
    Featured Image
    The blog post details using the `lsblk --json` command in Linux to programmatically manage block devices. It explains `lsblk`'s importance in viewing device relationships and its JSON output option for easy scripting. The article provides simple `lsblk` usage examples, an executable script using `jq` to extract device names and sizes, and discusses the command's integration into automation scripts for efficient storage management in system administration and DevOps.
  • Posted on
    Featured Image
    The article explores using `systemd-run` to manage transient services in Linux via Bash scripts. Demonstrating the tool's ability to manage tasks without permanent service files, it covers practical usage scenarios like running Python scripts as services and logging system memory, enhancing script functionality with `systemd`'s features like auto-restarting and logging.
  • Posted on
    Featured Image
    Learn how to optimize `find -exec` command in Linux by using `+` for batching, which processes multiple files together. This method speeds up executions and minimizes system load by reducing the number of commands initiated. Examples include deleting files or altering permissions in batch mode, demonstrating significant performance improvements.
  • Posted on
    Featured Image
    The blog "Minimizing `fork()` Calls in Linux by Combining Commands" explains how to optimize Bash scripts by reducing `fork()` system calls, which create new processes. By merging commands, using built-in commands, and employing control operators like `&&` and `;`, the blog demonstrates enhancing script efficiency and system resource conservation. Practical examples and strategies effectively illustrate the concept, crucial in resource-limited environments.
  • Posted on
    Featured Image
    GNU Parallel in Bash optimizes task execution by leveraging multiple CPU cores for simultaneous job processing, enhancing speed and productivity. It handles task distribution automatically across available cores, continuing allocation as cores free up. Installable via most Linux repositories, it simplifies shell command execution. For instance, counting lines in text files or converting image formats can be efficiently processed with simple commands like `ls *.txt | parallel wc -l` or `ls *.png | parallel convert {} {.}.jpg`. Scripts, like resizing images in parallel, demonstrate its potential to significantly reduce processing times, making it invaluable for efficient computational task management.
  • Posted on
    Featured Image
    The article discusses the benefits of using `awk` alone over combining `grep` with `awk` for text processing in Linux. `grep` searches for specific patterns, while `awk` provides comprehensive text manipulation capabilities. Replacing `grep | awk` pipelines with a single `awk` command simplifies scripts, enhances performance, and improves script readability and maintainability, with practical examples and scripts provided to demonstrate these advantages.
  • Posted on
    Featured Image
    Firejail is a sandboxing tool for Linux that isolates program environments, enhancing security by restricting unauthorized filesystem access. Ideal for handling untrusted scripts or testing, it uses command prefixes for operation, ensuring scripts only access specific necessary directories. This secures Linux applications efficiently against potential script-related vulnerabilities.
  • Posted on
    Featured Image
    The article guides on using IPTables for rate limiting in Linux, outlining its role as a firewall tool to control network traffic and enhance security. It details the use of the `limit` module to manage connection rates, such as limiting SSH to three per minute, and includes script examples for setup and configuration. This ensures effective traffic management and protects against service abuse and DDoS attacks.
  • Posted on
    Featured Image
    The article explains how to use `strace`, a Linux tool for debugging scripts by tracing system calls and signals. It covers `strace`'s functionality in capturing syscall-level interactions, which aids in diagnosing errors and inefficiencies that are tough to find at the script logic level. Key flags like `-o`, `-e`, `-p`, and `-f` are detailed, with examples illustrating `strace` in action on simple script operations such as file reading and writing.