Found 1436 Articles for Linux

Split a File at Given Line Number

Pradeep Jhuriya
Updated on 04-Jan-2023 11:41:44

2K+ Views

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 More

How to Record Linux Terminal Sessions?

Pradeep Jhuriya
Updated on 04-Jan-2023 11:38:02

5K+ Views

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 More

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

Pradeep Jhuriya
Updated on 04-Jan-2023 11:20:16

570 Views

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 More

Aborting a shell script on any command fails

Satish Kumar
Updated on 03-Jan-2023 11:10:33

11K+ Views

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 More

Working with Zip Command in Linux

Satish Kumar
Updated on 03-Jan-2023 11:09:03

2K+ Views

Overview The zip command is one of the most useful tools available on any operating system. It allows you to compress multiple files into a single compressed archive file. You can then decompress that archive file using the unzip command. This tutorial will show you how to use the zip command to create and extract archives. In this tutorial, we’ll be looking at the zip command-line tool in Linux. We will learn how to use it for creating and extracting archives. The zip command is a part of the GNU core utils package. It can be used to create and ... Read More

Killing all members of a process group in Linux

Satish Kumar
Updated on 03-Jan-2023 11:06:59

893 Views

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 More

Create a file of certain size in Linux

Satish Kumar
Updated on 03-Jan-2023 11:05:00

17K+ Views

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 More

Https connection using curl on Linux

Satish Kumar
Updated on 03-Jan-2023 11:03:08

5K+ Views

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

How to add a Column of Numbers in Bash?

Satish Kumar
Updated on 03-Jan-2023 11:00:17

1K+ Views

Overview This article examines how to total up numeric columns of data in a bash shell, looking at the bash tools available for the task and comparing their speed. Using The awk Tool We’ll start by calculating the sum of the values in a particular column using the awk (awk) program. $ awk '{Total=Total+$1} END{print "Total is: " Total}' numbers.csv Total is: 49471228 Let’s now take a look at the timing using the “time” command − $ time awk '{Total=Total+$1} END{print "Total is: " Total}' numbers.csv Total is: 49471228   real 0m0.228s user 0m0.141s sys 0m0.047s When The ... Read More

Extracting a substring using Linux bash

Satish Kumar
Updated on 03-Jan-2023 10:58:15

5K+ Views

Overview Extracting a substring from a string is a basic and common operation of text processing in Linux. We're looking at different ways to extract substrings from strings using the Linux command line here. Extracting an Index-Based Substring Let’s first take a quick glance at how to extract index-based substring using four different methods. Using the cut command Using the awk command Using Bash’s substring expansion Using the expr command Next, we’ll see them in action. Using The cut Command We can extract characters starting at position N through position M from the input string using "cut" command. ... Read More

Advertisements