Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Linux Articles
Page 39 of 134
Killing all members of a process group in Linux
As a Linux system administrator, dealing with processes is a frequent task. Generally, they're easy to stop, however in certain cases − when there are large numbers of processes within the same groups − additional steps might be needed. We'll take a closer look at how to manage processes using the concept of process groups and how to terminate all processes that belong to one particular group efficiently. Process Groups A process group in Linux is a collection of related processes that share the same Process Group ID (PGID). Each process group has one group leader whose ...
Read MoreAborting a shell script on any command fails
By utilizing Bash scripts, we can have access to a powerful programming language. Writing such scripts is an efficient way to run several commands one after the other. However, by default, even if one command fails, the others will still be executed, which can lead to unexpected behavior or data corruption. We'll learn how we can add some safeguards so that these errors don't happen. The example code has been tested in Bash and should also work for other POSIX-compatible shell environments. The Problem Let's first take a look at how Bash handles error messages by default. ...
Read MoreHow To Script "Yes" When Installing Programs on Linux?
Installing programs on Linux often requires user interaction, such as agreeing to license terms or confirming installation options. To automate this process, you can use scripts that automatically provide the desired responses. This article explains how to script "yes" responses when installing programs on Linux using command line tools. Using the "yes" Command The yes command is a built-in utility that continuously outputs a specified string, making it perfect for automated responses to installation prompts. Basic Usage The yes command is part of the coreutils package, which is pre-installed on most Linux distributions. To use it, ...
Read MoreHow to Record Linux Terminal Sessions?
Recording Linux terminal sessions is valuable for documenting commands, troubleshooting, sharing workflows, and creating tutorials. This article explores three popular methods to capture terminal activity: the built-in script command, the ttyrec/ttyplay combo, and the modern asciinema tool. Method 1: Using the script Command The script command is a built-in Linux utility that captures all terminal output to a plain text file. It records everything displayed in the terminal, including commands, output, and control characters. Basic Usage To start recording, run script followed by the output filename: $ script my_session.txt Script started, file is my_session.txt ...
Read MoreSplit a File at Given Line Number
The split command in Linux is a powerful utility used to divide large files into smaller, more manageable chunks. This is particularly useful when dealing with log files, databases, or large datasets that need to be processed in smaller portions or transferred across systems with size limitations. How the Split Command Works The split command reads an input file and creates multiple output files based on specified criteria such as number of lines, file size, or patterns. By default, it generates files with alphabetical suffixes starting from aa, ab, ac, and so on. Basic Syntax ...
Read MoreInsert a Line at Specific Line Number
Inserting a line at a specific line number in a file is a common task in Linux system administration and text processing. The sed (stream editor) command provides a powerful and flexible way to accomplish this task efficiently from the command line. What is sed? sed stands for "stream editor" and is a command-line utility that allows you to modify file contents by applying various operations such as replacing text, deleting lines, and inserting lines. It processes text line by line, making it ideal for automated text processing and bulk file modifications. Basic Syntax for Line Insertion ...
Read MoreDetach Screen From Another SSH Session
Screen is a terminal multiplexer in Linux that allows you to create multiple virtual terminal sessions within a single SSH connection. Sometimes you may need to detach or manage screen sessions that are running in other SSH connections, especially when working on shared servers or when sessions are accidentally left running. Listing Active Screen Sessions Before detaching any screen session, you need to identify which sessions are currently running. Use the following command to list all active screen sessions: screen -ls This will display output similar to: There are 2 screens on: ...
Read MoreRun a Function in a Script from the Command Line on Linux
BASH (Bourne Again Shell) is a Unix shell and command language widely used in Linux and Unix-like operating systems. One powerful feature of BASH is the ability to create and use functions within script files. Functions are reusable blocks of code that perform specific tasks and can be executed from within the script or directly from the command line. Prerequisites Before we begin, you will need − A Linux system with a command line interface (or SSH access). A script containing a function you want to run (your custom script). The required permissions to execute the ...
Read MoreLimiting Process Resource Consumption in Unix
In Unix-based operating systems, managing process resource consumption is crucial for system stability and performance. When processes consume excessive resources, they can cause system slowdowns, unresponsiveness, or even crashes. Unix provides several mechanisms to control and limit resource usage by individual processes or groups of processes. The two primary methods for limiting process resource consumption are the ulimit command for per-process limits and cgroups (control groups) for managing resource allocation across groups of processes. These tools help system administrators maintain optimal system performance and prevent resource starvation. Using the ulimit Command The ulimit command sets resource limits ...
Read MoreRemove Line Endings From a File on Linux
Line endings are special characters that mark the end of a line in a text file. On Unix-based systems like Linux, the line ending is represented by a single newline character (). On Windows, the line ending is represented by a combination of a carriage return (\r) and a newline character (), which is referred to as CRLF. Sometimes, you may need to remove line endings from a file for various reasons. For example, you may want to remove line endings before using it as input to a command that expects a single line of input, or to make ...
Read More