Found 1436 Articles for Linux

Implement a Counter in Bash Script on Linux

Pradeep Jhuriya
Updated on 17-Jan-2023 17:11:01

3K+ Views

Introduction As a Linux enthusiast, you may have come across situations where you needed to perform some repetitive tasks and wished if you had a counter that could keep track of the number of times you performed a certain task. Well, guess what? Bash scripting allows you to do just that! In this article, we will discuss how you can implement a counter in your Bash scripts and use it to keep track of the number of times a certain task is performed. But before we dive into the implementation details, let's first understand what a counter is and why ... Read More

Count Duplicate Lines in a Text File on Linux

Pradeep Jhuriya
Updated on 17-Jan-2023 17:07:45

10K+ Views

Introduction There are several reasons why you might want to count the number of duplicate lines in a text file on a Linux system. For example, you may want to find out if there are any errors in your data or you may want to optimize your file by removing duplicates. Whatever the reason, Linux provides several tools and commands you can use to do this. Preparation Before we dive into the commands, let's first create a text file with a few duplicate lines that we can use for testing. Open a terminal and create a new file using the ... Read More

Exclude Multiple Patterns With Grep on Linux

Pradeep Jhuriya
Updated on 22-Oct-2023 12:58:24

19K+ Views

Introduction Grep is a powerful command line utility on Linux that allows users to search for patterns in text files. It is widely used for tasks such as searching log files for specific strings or patterns, searching for specific lines in a configuration file, or extracting information from a large dataset. One of the useful features of grep is the ability to exclude multiple patterns from the search. This can be useful when you want to filter out irrelevant or unwanted results from your search. In this article, we will discuss how to exclude multiple patterns with grep on Linux. ... Read More

How to Use the Paste Command on Linux?

Pradeep Jhuriya
Updated on 17-Jan-2023 17:00:51

343 Views

Introduction The Paste command in Linux is a useful tool for merging multiple files or lines of text into a single file or output. It is commonly used in conjunction with the cut command, which allows users to cut specific lines or sections of text and paste them elsewhere. In this article, we'll explore the various options and usage scenarios for the paste command in Linux, as well as demonstrate how to use it with examples and output. What is the Paste Command? The Paste command is a utility on Unix and Linux operating systems that allows users to merge ... Read More

Measure CPU usage for a process on Linux?

Pradeep Jhuriya
Updated on 12-Jan-2023 11:10:17

6K+ Views

Introduction On modern multi-core CPUs, it is often useful to know the CPU usage of individual cores for a particular process. This can be helpful for identifying bottlenecks in the system, or for understanding the workload distribution across CPU cores. In this article, we will see how to measure separate CPU core usage for a process on Linux using various command line tools. Measure CPU Core Usage using top Command The top command is a commonly used tool for monitoring system resources, including CPU usage. By default, top displays the overall CPU usage for all cores, but it also provides ... Read More

Partitioning Disks in Linux

Pradeep Jhuriya
Updated on 12-Jan-2023 11:05:46

2K+ Views

Introduction In Linux, a disk partition is a logical division of a hard disk drive (HDD) or solid-state drive (SSD) that is used to manage data in a more organized manner. Partitions allow you to separate data by function, such as separating system files from user files, or to set up multiple operating systems on a single physical disk. There are several tools available for creating and managing disk partitions in Linux, including fdisk, parted, and gparted. In this article, we will focus on using fdisk and parted as they are widely available on most Linux distributions. Creating a Partition ... Read More

Delete Multiple Files at Once in Bash

Pradeep Jhuriya
Updated on 12-Jan-2023 10:56:15

6K+ Views

Introduction Bash is a Unix shell and command language that is commonly used on Linux systems. It allows users to perform a variety of tasks, including deleting files. In this article, we will look at how to delete multiple files at once in Bash on a Linux system. We will cover the basic syntax for deleting multiple files, as well as some advanced techniques for deleting specific types of files or forcing the deletion of write-protected files. Using rm Command in Linux The rm command is used to delete files in Bash. To delete a single file, you can use ... Read More

Creating a Temporary File in Linux

Pradeep Jhuriya
Updated on 12-Jan-2023 10:54:21

5K+ Views

Introduction In Linux, it is often necessary to create temporary files for various purposes, such as storing intermediate data during processing or storing configuration information for a script. Temporary files are usually created in the /tmp directory, which is a standard location for storing temporary files on most Linux systems. Creating a Temporary File in Linux There are several ways to create a temporary file in Linux. One of the most common methods is to use the mktemp command, which creates a unique temporary file and prints the file name to the console.SyntaxTo create a temporary file using mktemp,  use the ... Read More

Uses of Exec Command in Linux

Pradeep Jhuriya
Updated on 19-Jul-2023 15:32:52

2K+ Views

Introduction The exec command is a built-in command in the Unix and Linux shell that allows a user to execute a command or a script in place of the current shell. This means that the exec command is used to replace the current shell process with a new process, which can be a command or a script. The exec command is useful in shell scripts when you want to execute a command or a script and then exit the current shell. Syntax of exec command −Example $ exec: exec [-cl] [-a name] [command [argument ...]] [redirection ...] Why should ... Read More

Write a Bash Script that Answers Interactive Prompts

Pradeep Jhuriya
Updated on 05-Apr-2023 11:32:48

4K+ Views

Introduction Interactive prompts are a common feature in many Linux command-line tools and utilities. These prompts allow the user to provide input or make a selection in order to proceed with a task. While interactive prompts can be useful in some situations, they can also be a nuisance when running scripts or automating tasks. In these cases, it can be helpful to know how to automatically answer interactive prompts. Handling Interactive Prompts There are several ways to automatically answer interactive prompts in Linux. One method is to use the expect command, which is a scripting language specifically designed for automating ... Read More

Advertisements