In today’s article, we’re going to learn how you can go to a specific line in Nano. It’ll be an easy article, perhaps even a fairly brief article. There are a just a couple of ways to cover, so it won’t take all that much time or space.
Often, when things like scripts throw an error, they’ll tell you on which line number the error happened. There are often hundreds or thousands of lines in complicated files and navigating to the correct line number is tedious, prone to error.
You can be pressing the down arrow for quite a while! So, why not note the line number where the error occurred and open the file at that specific line? It’s perfectly good sense! It’s such good sense that I figured I’d write an article about it.
You all know that I’m a Nano fan. You can read the ‘big’ Nano article here. If that’s not enough, this link is to a search for Nano across the entire site. There are nearly 30 articles that use Nano in them. I really am quite a fan.
Why am I a fan? Well, the first link will probably tell you that, but I like it because it’s simple. Nano’s starting to be fairly universal. It’s light and that’s why I like it – it’s only meant for quick text file edits.
Nano’s not really the right tool for writing a book, nor would I want to use it to write large scripts or for programming. For what it is, it’s great. If it’s not great, odds are good that you’re not using it as the tool it is. Sure, it’ll work for other things, but it excels at being what it is – a quick text editor in the terminal.
Nano is a terminal-based tool. So, you obviously need to have an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open. Tada! (That’s mostly copy/paste from previous articles, but I do sometimes mix it up a little!)
With your terminal open, let’s show you how to go to a specific line in Nano. It’s pretty easy, and we’re going to use a file most users will have. If you don’t have a ~/.bash_history
file, you can use any plain text file you want.
I suppose we should first make sure that you have Nano installed. To check, you can just look for the version. That’s done with:
nano -V
Your output should look something like:
If Nano isn’t installed, and you’re using any mainstream distro, it’s certainly in your default repositories. You can install it like you would any other piece of software in the repositories.
Now, there are two ways to open and go to a specific line in Nano. The first is probably the easiest. Using our ~/.bash_history
as an example, the command looks like this:
nano +25 ~/.bash_history
Where you see the +25
flag, that’s the place where you specify the line number to start with when you open Nano. You can use any number you want, provided there are that many lines in the file you’re intending to edit.
The next way is also easy. Using your keyboard, press CTRL + Shift + –. Nano will then present you with the chance to enter in a specific line. It looks like a lot like this:
So, now you have two ways to go to a specific line in Nano. I told you that it was going to be easy! Nano is awesome.
There’s another article! It’s on one of my favorite subjects – Nano. Now you’ve learned how to go to a specific line in Nano, which is a pretty handy trick to have in your toolbox. It can save you all sorts of time, and not just time scrolling. It means you aren’t paying attention to the rest of the fluff and you can concentrate better, or so it seems to me. For what it is, Nano is my favorite plain text editor and it’s remarkably useful at times.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.
Today we'll cover one way to enable or disable your network interface in the Linux…
Today's exercise is a nice and simple exercise where we check your NIC speed in…
Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…
I think I've covered this before with the ls command but this time we'll count…
Today we'll be learning about a basic Linux command that's known as 'uname' and it…
If you've used hardinfo in the past, it may interest you to know that hardinfo…
View Comments
Trying to find a line in nano to edit rkhunter, update_mirrors=0, to, update_mirrors=1, I get the config open, but can't "find" the line, always end up with no results. Very new to this.
You're not subscribed to this conversation, so I have no idea if you'll get my response.
Experience tells me that folks don't revisit to see the answer and only do if they're subscribed.
My suggestion to you is that you come visit us at https://linux.org where there's a helpful and welcoming community, perhaps the friendliest Linux community online. It'll be easier to help you there.
I do indeed welcome questions and comments, but I'm not all-knowing.
I'm also a big fan of Nano, the article is very good