nano — Open Files at a Given Line Number

The nano text editor is included in Debian-based operating systems. Because Ubuntu is based on Debian you’ll find nano pre-installed as well. The nano editor comes in handy when working in environments where you don’t have a user interface. For example, in server environments or using remote connections via the command line.

Editing large files with nano can be tedious, especially when the line of interest is hundreds of lines away from the start. This tutorial shows you how to open a file with nano at a given line number.

Open Files in nano Editor at Line Number

You can jump to a specific line in nano using nano +<line-number> app.js. The “plus” flag tells nano to jump to line n for the opening file:

# open my-file.js at line 377
nano +377 my-file.js  

Nano jumps to the last line of the selected file if you’re providing a line number that exceeds the total number of lines.

Notice: you can’t use a negative jump like nano -1 app.js to jump to the last line.

Enjoy!

Explore the Library

Find interesting tutorials and solutions for your problems.