We know that we can make use of the grep command to search for a particular pattern of characters in all the lines of a file or multiple files. The grep command performs a case-insensitive search for words in a file.Let’s see a simple example where we will grep a pattern in all the files that are present in a directory.Commandgrep -i ‘lp’ Sample*OutputSample: The sample was printed via the internet. Sample: I believe lp cares about what the device is. Sample1: This was printed via the internet. Sample1: I believe lp cares about what the device is. Sample2: This ... Read More
In order to be able to grep multiple lines of pattern present in a file, we will make use of the number of grep command that Linux provides us with. But first, we must understand what a grep command is and how to use it 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.Normally, the pattern that we are trying to search in the file ... Read More
While there are plenty of ways to print and make use of specific words from a particular file in a Linux directory, when we talk about grepping a particular word and then replacing it with some other word, then we will need to mix certain Linux utility commands.The two Linux utility commands that we must be aware of are −find − used to locate a particular file or directorysed −short for stream editor and is used to perform functions like searching, editing and replacing.In order to solve the problem of grep and replace a particular word we will make use ... Read More
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.Normally, the pattern that we are trying to search in the file is referred to as the regular expression.Syntaxgrep [options] pattern [files]While there are plenty of different options available to us, some of the most used are −-c : It lists only a count of the lines that match a pattern -h : displays the matched lines only. ... Read More
Whenever we want to get an update about a specific process or different process we make use of the ps command which is short for “Process status” that tells us about the state of the current process and its characteristics and a whole lot more.When clubbed with several flags and commands we can enhance the ps command to output the start time of different processes that are running on a particular Linux machine.The command to print the time of long running processes in increasing order is shown below −For Ubuntu and other Linux based Systems −ps -eo pid , lstart ... Read More
We make use of the bash files to store different variables that we normally refer to as the environment variables. We can later access these variables easily by just printing them with the help of the echo utility command tha linux provides us with.ExamplePrint the $PATH environment variable.Commandecho $PATHOutputimmukul@192 src % echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/Us ers/immukul/.cargo/binNow as we can see that the PATH environment variable is made of different directories, and suppose we want the last file name from the path variable.In that case, we would make use of the base name command utility that Linux provides us with.The base name ... Read More
Linux find statement is one of the most widely used statements that allows us to walk a file hierarchy. It is used to mostly find a specific file or directories and we can also append different other Linux statements or flags along with it to enhance or do a complex operation.Let’s explore an example of a find statement to understand it better.In the linux code shown below I am trying to search for a file inside my Downloads folder, and for that I am making use of the find statement.find sample.shOutputsample.shNotice that if the find command is able to locate ... Read More
In order to get the width and height of the Linux console in Python, there are different modules available that we can make use of. Two of them are the os module and the subprocess module.In the case of the os module, we make use of the popen() method that is used to open a pipe to and from command which will help in retrieving the width and height of the Linux window.Consider the code for the same shown below −import os rowSize, columnSize = os.popen('stty size', 'r').read().split() print(rowSize) print(colSize)Save the above shown code in a file with a ... Read More
Java supports two types of right shift operators. The >> operator is a signed right shift operator and >>> is an unsigned right shift operator. The left operands value is moved right by the number of bits specified by the right operand.Signed right shift operatorThe signed right shift operator '>>' uses the sign bit to fill the trailing positions. For example, if the number is positive then 0 will be used to fill the trailing positions and if the number is negative then 1 will be used to fill the trailing positions.Assume if a = 60 and b = -60; ... Read More
In Java final is the access modifier which can be used with a filed class and a method.When a method if final it cannot be overridden.When a variable is final its value cannot be modified further.When a class is finale it cannot be extended.Extending a final classWhen we try to extend a final class that will lead to a compilation error saying “cannot inherit from final SuperClass”ExampleIn the following Java program, we have a final class with name SuperClass and we are trying to inherent it from another class (SubClass).final class SuperClass{ public void display() { ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP