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
-
Economics & Finance
Articles by Mukul Latiyan
Page 10 of 37
How to insert a text at the beginning of a file in Linux?
In Linux, there are several ways to insert text at the beginning of a file. The most common and efficient method uses the sed command, which stands for stream editor. This command performs various operations like find, replace, insert, and delete on files without opening them in an editor. Using the sed Command The sed command can modify files in-place using the -i flag, making it perfect for inserting text at the beginning of files. Let's explore this with a practical example. Example Setup Consider a directory d1 containing text files. First, let's check the directory ...
Read MoreHow to install the latest version of Git on CentOS 7.x/6.x?
Installing the latest version of Git on CentOS can be accomplished through multiple approaches. CentOS repositories often contain older versions of Git, so these methods help you install more recent versions with enhanced features and security updates. Approach 1: Using IUS Community Repository The IUS Community Repository provides updated packages for Enterprise Linux distributions. This is the most straightforward method for getting a recent Git version. Commands yum install epel-release yum remove git rpm -U https://centos7.iuscommunity.org/ius-release.rpm yum install git2u git --version Output immukul@192 lib % git --version git version 2.29.2 ...
Read MoreHow to invert a grep expression on Linux?
The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It is one of the most used Linux utility commands to display the lines that contain the pattern that we are trying to search. To invert a grep expression means to display all lines that do NOT match the specified pattern, which is accomplished using the -v option. Basic Grep Syntax grep [options] pattern [files] Common Grep Options -c : Lists only a count of the lines that match a pattern -h : Displays ...
Read MoreHow to iterate over a list of files with spaces in Linux?
In order to iterate over a list of files we will need to make use of the find command that Linux provides us with. When dealing with filenames containing spaces, special handling is required to avoid issues with word splitting. Linux find statement is one of the most widely used commands that allows us to walk a file hierarchy. It is used to find specific files or directories and we can append different flags and options to enhance functionality or perform complex operations. Basic Find Command Example Let's start with a simple example of the find statement: ...
Read MoreHow to know what the 'errno' means in Linux?
Errno is a global variable in Linux and Unix systems that indicates the type of error that occurred during system calls and library function execution. When a system call or library function encounters an error, it sets the errno variable to a specific integer value that corresponds to the type of error. This mechanism allows developers to identify and handle different types of errors programmatically. The errno variable is defined in the header file and is thread-local in modern implementations. Each error code has both a numeric value and a symbolic constant name written in uppercase letters. ...
Read MoreHow to limit the number of results returned from grep in Linux?
The grep command in Linux is a powerful text search utility used to filter and search for specific patterns in files. When working with large files or datasets, you may want to limit the number of results returned to make the output more manageable and focused. The grep command searches for lines containing a specified pattern (regular expression) and displays matching results. By default, it returns all matching lines, but Linux provides several options to limit and control the output. Syntax grep [options] pattern [files] Common Grep Options Option Description ...
Read MoreHow to list all users in a Linux group?
In order to understand the commands to list all users in a Linux group, you first need to know how to list all users on the system. There are several ways to accomplish this, and one effective method is using the compgen command. The compgen command is a Linux utility that lists all commands executable in the terminal. When used with the -u flag, it displays all users present on the Linux system. compgen -u Output root daemon bin sys sync games man lp mail news uucp proxy www-data backup ... ...
Read MoreHow to list down all the available commands and aliases on Linux?
Linux provides a vast collection of commands and aliases that users can utilize in the terminal. These commands serve different purposes and can be executed from anywhere in the command line interface. Understanding how to list available commands and aliases is essential for efficient Linux system administration and usage. There are several approaches to discover all available commands in Linux. You can write custom shell scripts or use built-in shell functions designed for this purpose. The most effective method involves using the compgen command, which is a bash builtin specifically designed to list various shell components. Using the ...
Read MoreHow to list running screen sessions on Linux?
Screen (also known as GNU Screen) is a terminal multiplexer that allows you to start a screen session and open multiple windows within that session. A key advantage is that processes running in Screen continue to execute even when their window is not visible or when you disconnect from the session. Installing Linux Screen If the screen package is not already installed on your Linux distribution, you can install it using the appropriate command for your system. For Ubuntu and Debian sudo apt update sudo apt install screen For CentOS and Fedora ...
Read MoreHow to match two strings that are present in one line with grep in Linux?
The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It is one of the most used Linux utility commands to display lines that contain the pattern we are searching for. When we need to find lines containing multiple strings, we can combine grep commands or use pattern matching techniques. The pattern we search for is referred to as a regular expression, and grep provides several methods to match multiple strings on the same line. Basic Grep Syntax grep [options] pattern [files] Common Grep Options ...
Read More