In Linux, the command history is a record of previously executed commands. The command history is stored in a file called . bash_history, which is located in the home directory of each user. The history command can be used to view the command history, and the history command can also be used with other commands, such as grep, to search for specific commands in the history. The commands in the history are assigned a number, which can be used to quickly execute a previous command by prefixing it with an exclamation mark (!). For example, typing "!123" will execute the ... Read More
A simple service in Linux is a program that runs in the background and performs a specific function or set of functions. These programs can be started automatically at boot time, and can be controlled using the command line or through a system service manager such as systemd or Upstart. To create a simple service in Linux, you would first write the program that performs the desired function. This program should be designed to run in the background and to continue running even after the terminal window or SSH session is closed. Next, you would create a script that can ... Read More
There are several ways to display a GUI notification from a shell script in Linux, but one common method is to use the notify-send command. This command is part of the libnotify library and is typically pre-installed on most Linux distributions. An example of how to use notify-send to display a notification with a title of "Hello" and a message of "World" is − notify-send "Hello" "World" You can use the command in your shell script by simply adding the command to it, or assign the notification text to a variable and use it message="This is your reminder" ... Read More
The optimal block size to use with the dd command in Linux depends on the specific use case and the hardware that you are working with. However, as a general rule of thumb, it is best to use a block size that is a multiple of the disk's physical block size, as this can lead to better performance. To determine the physical block size of a disk, you can use the fdisk command with the -l option. This will list all the partitions on the disk, along with the start and end cylinders, and the block size. For example, to ... Read More
Logs are a crucial component of any Linux system, as they provide a record of system activity, including system events, user actions, and system processes. Log checking, or log monitoring, is the process of regularly reviewing log files to identify any unusual or suspicious activity, such as failed login attempts, system crashes, or security breaches. Log checking is important for maintaining the security and stability of a Linux system, as it allows administrators to quickly identify and troubleshoot problems, and detect and respond to potential security threats. Basic journalctl Commands journalctl is a command line utility for viewing and managing ... Read More
The ps command in Linux is used to display information about the running processes on a system. It provides a snapshot of the current processes, including the process ID (PID), the user that owns the process, the percentage of CPU and memory usage, and the command that started the process. By default, ps only shows information about processes that are running in the same terminal session as the ps command. However, using various options and command line arguments, you can customize the output to show information about all processes running on the system, or even remotely. Listing All Processes To ... Read More
Bash globbing is the process of using wildcard characters to match multiple filenames or paths. Bash provides several special characters that can be used for globbing, such as *, ?, and []. The * character is a wildcard that can match zero or more characters in a filename or path. For example, the command ls * would list all files in the current directory, while the command ls *.txt would list all files with the ".txt" extension in the current directory. The ? character is similar to the * character, but it only matches a single character. For example, the ... Read More
You can use the find command in Linux to search for files ending with CRLF, and the dos2unix command to convert those files to use LF line endings. To search for files ending with CRLF, you can use the following command − find /path/to/search -type f -exec grep -Iq . {} \; -and -exec grep -Il $'\r' {} + This command searches for all regular files in the directory "/path/to/search" and its subdirectories, and prints the names of the files that contain CRLF line endings. Once you have identified the files that need to be converted, you can use ... Read More
In this article, we will learn how to generate IP addresses from the CIDR address. Methods Used The following are the various methods to accomplish this task − Generating IPv4 Network addresses Generating IPv6 Network addresses Accessing IP addresses of the CIDR address Method 1: IPv4Network Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Use the import keyword to Import the ipaddress module. Use the ip_network() function(returns the type of network of the address ) of ipaddress module to get the IP addresses from an input CIDR address(IPv4Network) Use the ... Read More
In this article, we will learn a python program to find the profit or loss when the cost price CP of N items is equal to the selling price SP of M items. Assume we have taken N, and M values which represent the cost price of N items are equal to the selling price of M items. We will now calculate the profit or loss percentage. Formula profit/loss = ( (Cost Price) - (Selling Price) ) / (Selling Price) * 100 What is the Selling Price(SP)? The price a consumer pays to purchase a product or a commodity ... Read More