How to display/print nth line in Linux Command Line [Quick Tip]

Problem:

Imagine a scenario where you need to print or display only the nth line of the file. For e.g, suppose you have a file with 50000 line and you want to print just the 100th line.

Solution.

My favorite way to do so is by using a combination of tail and head command. Here is the commands that can be used for the mentioned purpose:

tail -n +100 filename | head -n1
Tail -n +100 gives all the lines starting from 100th line. Then we use head -n1 which gives the first line. A combination of bot gives the 100th line.
The example can be made generic by replacing 100 by your desired value.

How to find all files containing specific text in Linux?

One of the common commands that I use most frequently in my day-to-day Linux life is for finding files that contains a particular text. Take for an example that I want to search all the files in the current directory that contains string “Hello! this is my file”. The command that is use mostly is this:

find . -type f -exec grep -il 'Hello! this is my file' {} ; 

This search ignores the cases. If you want to search with definite cases (upper or lower) remove the “-i” from grep. You can replace “.” (dot, which means current directory) by the path of the directory in which you want to conduct the search. If you want to search in the whole system then use “/” (it means root directory).