Open Source Articles

Page 38 of 123

Aborting a shell script on any command fails

Satish Kumar
Satish Kumar
Updated on 17-Mar-2026 14K+ Views

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 More

How To Script "Yes" When Installing Programs on Linux?

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 1K+ Views

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 More

How to Record Linux Terminal Sessions?

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 7K+ Views

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 More

Split a File at Given Line Number

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 5K+ Views

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 More

Insert a Line at Specific Line Number

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 21K+ Views

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 More

Detach Screen From Another SSH Session

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 596 Views

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 More

Run a Function in a Script from the Command Line on Linux

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 16K+ Views

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 More

Limiting Process Resource Consumption in Unix

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 414 Views

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 More

Remove Line Endings From a File on Linux

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 6K+ Views

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

Here Document And Here String in Bash on Linux

Pradeep Jhuriya
Pradeep Jhuriya
Updated on 17-Mar-2026 2K+ Views

Here documents and here strings are powerful Bash features that allow users to pass multi-line input to commands without using external files. These redirection mechanisms are essential for shell scripting, enabling clean and readable code for tasks involving multi-line text processing, configuration generation, and command automation. What is a Here Document? A here document (heredoc) is a type of input redirection that allows you to specify multiple lines of input for a command using the

Read More
Showing 371–380 of 1,225 articles
« Prev 1 36 37 38 39 40 123 Next »
Advertisements