Oli Warner About Contact Oli on Twitter Subscribe

Nano: Open a file at a specific position

Sunday, 17 October 2010 linux nano

Nano isn’t the best editor but it does a fairly good job at staying out the way and letting you edit or view things without needing a cheat-sheet of cryptic keyboard shortcuts. However, what do you do when you have a 50,000 line document and you want to get a specific line somewhere near the middle?

It’s been said (and shouted) at least a billion times but you need to RTFM. Not enough people do. Even I’m guilty; first I Googled and then asked on IRC. Just ask nano for --help and you’ll see it’s not that hard!

oli@bert:~$ nano --help
Usage: nano [OPTIONS] [[+LINE,COLUMN] FILE]...

Option		GNU long option		Meaning
 -h, -?		--help			Show this message
...

So if I was hunting for line 23971 in /var/lib/dpkg/status (as I just was), I’d fire off:

sudo nano +23971 /var/lib/dpkg/status

And it works, as expected. Magic.