Nano: Open a file at a specific position

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?

Published 2010-10-17. Read 201 times. 1 Comment. Tagged: linux nano

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.

About Oli: I’m a Django and Python programmer, occasional designer, Ubuntu member, Ask Ubuntu moderator and technical blogger. I occasionally like to rant about subjects I should probably learn more about but I usually mean well.

Stay updated: Subscribe by RSS or Subscribe by Email.