Get Web Page Contents in a Shell Variable on Linux

Pradeep Jhuriya
Updated on 25-Jan-2023 10:29:19

3K+ Views

Introduction One of the most useful and powerful features of the Linux command line is the ability to manipulate text. This can be especially useful when working with web pages, as web page content can often be saved as plain text and then manipulated with command-line tools. In this article, we will explore how to insert the content of a web page into a shell variable in Linux. What is a Shell variable? A Shell variable is a value stored in memory and can be used by the shell (command-line interface) and other programs. Shell variables are usually defined in ... Read More

Append Contents of Multiple Files into One File on Linux

Pradeep Jhuriya
Updated on 25-Jan-2023 10:24:57

34K+ Views

Introduction There are many situations where you may need to combine the contents of multiple files into one file. For example, you may have a number of log files that need to be analyzed or you may want to merge multiple text documents into one document for easy editing. On Linux, there are several ways to aggregate the contents of multiple files into a single file, and in this article, we'll explore some of the most popular and effective methods. Method 1: Use the cat command The "cat" command is a powerful tool on Linux that allows you to view ... Read More

Guide to Generate Random Numbers in Linux

Satish Kumar
Updated on 25-Jan-2023 10:24:42

13K+ Views

In Linux, you can generate random numbers using the random or urandom files in the /dev directory, which are special files that generate random data. To generate a random number between 0 and 32767, you can use the command echo $((RANDOM)). To generate a random number within a specific range, you can use the command echo $((RANDOM%range+min)), where range is the size of the range and min is the minimum value of the range. Another way to generate random numbers in Linux is using the openssl command. The command openssl rand -base64 6 will generate a random base64 encoded string ... Read More

Capture SIGINT in Python

Vikram Chiluka
Updated on 24-Jan-2023 20:10:44

1K+ Views

In this article, we will learn how to capture SIGINT in Python and what has to be done after capturing it. When the signal module receives signals, it does a certain action. Besides that, it can capture the user's interruption through the keyboard using SIGINT. Modules Needed Signal Module The term "signal" refers to the process by which a program can receive information from the operating system. Additionally, the signals are sent to the program when the operating system detects specific events. By executing the following command at the terminal, the signal module can be installed − pip install signal ... Read More

Remove Lines from File A that Appear in File B in Linux

Satish Kumar
Updated on 24-Jan-2023 19:48:17

7K+ Views

You can use the grep command in Linux to remove the lines from file A that appear in file B. The basic syntax is − grep -v -f fileB.txt fileA.txt > outputFile.txt This command uses the -v option to invert the match, so that it returns lines that do not match those in file B. The -f option specifies the file containing the patterns to match. The output is redirected to a new file called outputFile.txt. Alternatively, you can use sed command sed -i '/$(grep -f fileB.txt fileA.txt)/d' fileA.txt This command uses the -i option to edit the ... Read More

Run Multi-Line Shell Code from Single Prompt

Satish Kumar
Updated on 24-Jan-2023 19:47:32

24K+ Views

You can run multi-line shell code at once by using a shell script or by using a command line tool such as the bash or sh command to execute the code in a single prompt. To create a shell script, you can use a text editor to write the code and save it with a .sh file extension. For example, you can create a file called "script.sh" and add the following code − #!/bin/bash echo "Hello, World!" echo "This is a shell script." Then you can run the script by using the command bash script.sh or sh script.sh. Another ... Read More

Run Script or Command as Another User in Linux

Satish Kumar
Updated on 24-Jan-2023 19:46:40

29K+ Views

There are several ways to run a script or command as another user in Linux. One way is to use the "su" command, which stands for "switch user." For example, to run a command as the user "john, " you would use the following syntax: "su john -c 'command'" Another way to run a command as another user is to use the "sudo" command, which stands for "superuser do." This command allows a user with proper permissions to run a command with the privileges of another user, typically the root user. For example, to run a command as the root ... Read More

Storing a Command in a Variable in a Shell Script

Satish Kumar
Updated on 24-Jan-2023 19:36:54

686 Views

In a shell script, you can store a command in a variable by using the syntax − variable_name="command" For example − current_date="date" You can then execute the command stored in the variable by prefixing it with $ − $current_date This will execute the command date. Storing the Command in an Array In a shell script, you can store a command in an array by using the syntax minus; array_name=( "command1" "command2" "command3" ) For example − commands=( "ls -l" "pwd" "date" ) You can then execute the commands stored in the array by using a ... Read More

Specify an Editor for Crontab on Linux

Satish Kumar
Updated on 24-Jan-2023 19:35:31

3K+ Views

The default editor for crontab on Linux is the vi editor. However, this can be changed by setting the VISUAL or EDITOR environment variable to the desired editor before running the crontab command. For example, to use nano as the editor for crontab, the command would be − export VISUAL=nano; crontab -e or export EDITOR=nano; crontab -e This will open the crontab file in nano for editing. Editor in Linux An editor in Linux is a program that allows users to create, view, and modify text files. There are many different text editors available for Linux, each with ... Read More

Monitoring Network Usage in Linux

Satish Kumar
Updated on 24-Jan-2023 19:33:59

15K+ Views

Linux monitoring refers to the process of tracking and analyzing various aspects of a Linux system's performance, such as CPU usage, memory usage, disk usage, network traffic, and system uptime. The goal of Linux monitoring is to detect and diagnose any issues that may be impacting the performance or stability of the system, and to identify and correct problems before they become critical. Network Monitoring Tools Some common network monitoring tools for Linux include − nload − is a command-line tool for monitoring network traffic on a Linux system. Speedometer − is a simple tool but with a different ... Read More

Advertisements