Whenever you are working with unreasonably large files, you might want to navigate from one line to another quite frequently. In that case, it gets quite troublesome to manually scroll the file up or down. Instead of this, there should be a way with which you can directly jump to the desired line. Therefore, today we will share with you two methods of going to the line X in the Nano editor on a Linux Mint 21 system.
Methods of Going to Line X in Nano in Linux Mint 21
There are two methods of going to a specific line in the Nano editor in Linux Mint 21 that are discussed below:
Method # 1: The Terminal Method
For this method, you do not need to separately open your file with the Nano editor. Rather, you can directly run a terminal command to go to a specific line of a file. For example, if we have a file named “testfile.txt” and we wish to jump directly to its second line, then we can run the following command:
This command will instantly open our specified file with the Nano editor while placing the cursor at the beginning of the second line as shown in the image below:
Method # 2: The Nano Editor Method
This method can be used when you have your target file opened with the Nano editor already. To use this method, you have to perform the following steps:
Step # 1: Press the Required Key Combination
We have already opened the file that we want to use for this method with the Nano editor as shown in the image below. Currently, the cursor is pointing at the beginning of this file or at the start of the first line of the file.
After opening this file, you need to press Ctrl + Shift + – key combination. Pressing this key combination will signal the Nano editor to ask you to enter a line number of your choice as shown in the following image:
Step # 2: Enter the Desired Line Number
Now, you can type any line number of your choice to which you wish to jump. In this case, we have typed “2” and then pressed the Enter key as shown below:
As soon as we did this, our cursor started pointing to the second line of our file as shown in the following image:
By picking any of the two methods explained above, you can instantly jump to the desired line of a file while using the Nano editor and hence you can make your file navigation experience very smooth.