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
Open Source Articles
Page 95 of 123
Run a Function in a Script from the Command Line on Linux
Introduction BASH (Bourne Again SHell) is a Unix shell and command language that is used frequently in Linux and other Unix-like operating systems. One of the useful features of BASH is the ability to create and use functions within script files. Functions are blocks of code that complete a specific task and can be executed from within the script or 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 ...
Read MoreDetach Screen From Another SSH Session
Introduction In Linux systems, it is possible to open multiple terminal sessions over SSH (Secure SHell). This can be very useful when working on a remote server and you want to keep multiple terminal shell windows open at the same time. However, there may be situations where you need to force detach/remove a screen session that is running in another SSH session. This can happen if you accidentally leave a screen session running on a remote server and then close your terminal window, or if you want to end a screen session that someone else on your team has left ...
Read MoreInsert a Line at Specific Line Number
Introduction Inserting a line at a specific line number in a file can be a useful task when you want to add new information to an existing file, or when you want to reorganize the contents of the file. In Linux, there are several ways to achieve this, but in this article, we will focus on using the sed command to insert a line at a specific line number. What is the sed command? sed stands for "stream editor" and it is a command line utility in Linux that allows you to modify the contents of a file or stream ...
Read MoreSplit a File at Given Line Number
Introduction Sometimes, it may be necessary to split a large file into smaller chunks for easier manipulation or for transfer to other systems. In Linux, the split command can be used to split a file into smaller files based on a specified number of lines. The split command is a utility that is used to split a file into smaller files, called chunks or pieces. The split command reads the input file, and writes the output files in the specified size or at the specified line number. By default, the split command creates files with a .x suffix, where x ...
Read MoreHow to Record Linux Terminal Sessions?
Introduction Sometimes it can be helpful to record a terminal session in Linux so that you can review the commands you ran, the output they produced, and any other text that was displayed in the terminal. In this article, we'll discuss three different ways to record terminal sessions in Linux − using the script command, using the ttyrec command, and using the asciinema tool. Method 1: Using the script command The script command is a simple and easy-to-use tool for recording terminal sessions in Linux. It captures all the text that is displayed in the terminal, as well as all ...
Read MoreHow To Script "Yes" When Installing Programs on Linux?
Introduction Installing programs on Linux can sometimes require user interaction, such as agreeing to license terms or specifying installation options. One way to automate this process is to use a script that automatically inputs the desired responses. In this article, we will discuss how to script the word "yes" when installing programs on Linux using the command line. Using the "yes" Command The yes command is a simple utility that repeatedly outputs a string, which can be useful for automated tasks such as accepting license agreements. Installing the "yes" Command Before we can use the yes command, we need to ...
Read MoreAborting a shell script on any command fails
Overview 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. Even if one command fails, the others will still be executed. We’ll learn how we can add some safeguards so that these errors don't happen. The example code has been tested in Bash. They 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. Let's say we have a simple shell script called "hello.sh" which prints out the ...
Read MoreKilling all members of a process group in Linux
Overview 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 “groups”. Also, how to terminate all processes that belong to one particular group. Process Groups A process grouping in Linux is a way that Linux processes share the same PIDs (process IDs). They are a set of related processes that share the same PIDs. Killing the ...
Read MoreCreate a file of certain size in Linux
Overview When using Linux, we often perform various operations on our own personal data. One common operation is to create an empty file of a specific size. There are many ways or command to achive this, here we’ll cover some of these methods − “dd” command dd − The dd command is a utility for copying files and converting the format of data. It can be used to create a file of a certain size by specifying the block size and the number of blocks with the bs and count options, respectively. The dd command reads data from an input ...
Read MoreHttps connection using curl on Linux
Overview curl is a command line tool that supports many different types of websites including https sites. It can be used to connect to any website, but it's most commonly used for connecting to web servers and retrieving data from them. In this tutorial we will learn how to use curl to make an HTTPS connection to a website. We will also see how to retrieve the contents of a file using curl. We’ll look at using curl to call an HTTP endpoint via HTTPS. What is Curl? Curl is a command line tool that allows users to transfer data ...
Read More