Linux Copy From Line Number to End of File

Jerry Jul 18, 2026

Copying from a specific line number to the end of a file in Linux is an essential task, especially when dealing with large text files. This process involves using a combination of commands, and knowledge of Linux's command-line interface can help users streamline their workflow.

the linux file system is shown with numbers and symbols in each column, which are labeled
the linux file system is shown with numbers and symbols in each column, which are labeled

This article will guide you through the process of copying content from a specific line number in a file to the end of that file. We will use command-line tools, primarily `sed` and `tail`. Let's dive right in.

a black and yellow flyer with linux commands
a black and yellow flyer with linux commands

Using `sed` to Copy from Line Number to EOF

`sed` is a powerful stream editor in Linux that can perform basic textual transformations on an input stream. It can be used to print specific lines from a file, which suit our requirement.

an image of a computer screen showing the functions for linux file permissions and how to use them
an image of a computer screen showing the functions for linux file permissions and how to use them

Here are the steps to use `sed` for copying from a line number to EOF:

Specifying the Line Number

an image of a computer screen with the text readme and other words on it
an image of a computer screen with the text readme and other words on it

To print line number 'n' to the end of the file, you can use the following command:

sed -n 'n,$p' file.txt

`'-n'` option tells `sed` to suppress automatic output. `'n,$p'` is the command that tells `sed` to print the line numbers from 'n' to EOF.

Using Line Numbers with a Range

Top 15 Kali Linux Commands Every Ethical Hacker Should Know🚀🎯
Top 15 Kali Linux Commands Every Ethical Hacker Should Know🚀🎯

If you want to print a range of lines from 'a' to 'b', you can use the following command:

sed -n 'a,bp' file.txt

`'a,b'` specifies the range. 'a' is the first line to print, 'b' is the last line to print. If 'b' is omitted, `sed` will print from line 'a' to EOF.

Using `tail` to Copy from Line Number to EOF

the most used linux command mind map
the most used linux command mind map

`tail` is a command that allows you to view the last part of a file. It can also print a specific range of lines, which can be used to copy the required content.

Here's how you can use `tail` for this purpose:

the differences between windows and linux
the differences between windows and linux
Top Linux Commands for Beginners
Top Linux Commands for Beginners
Simple way to Copy and Move a Large Number of Files using Terminal
Simple way to Copy and Move a Large Number of Files using Terminal
a screenshot of a computer screen with the text, chatsheet for beginners linux commands
a screenshot of a computer screen with the text, chatsheet for beginners linux commands
Learn Linux from Beginner to Advanced (Part-3) | File Viewing & Text Commands Cheat Sheet
Learn Linux from Beginner to Advanced (Part-3) | File Viewing & Text Commands Cheat Sheet
Linux Commands Cheat Sheet: 20 One-Liners to Navigate, Search & Fix Faster
Linux Commands Cheat Sheet: 20 One-Liners to Navigate, Search & Fix Faster
How to Search for a file in Linux
How to Search for a file in Linux
How to Count Lines, Words, and More in Linux - Make Tech Easier
How to Count Lines, Words, and More in Linux - Make Tech Easier
15 Linux Tricks & Hacks Every Hacker Should Know🚀
15 Linux Tricks & Hacks Every Hacker Should Know🚀
Linux File Permissions Explained (Part 18) | chmod, umask & ACLs Cheat Sheet
Linux File Permissions Explained (Part 18) | chmod, umask & ACLs Cheat Sheet

Specifying the Line Number

To print line number 'n' to the end, you can use the following command:

tail -n +n file.txt

`'-n' of a number' specifies the number of lines to output. When followed by a '+', it makes `tail` start printing from that line number.

Using Line Numbers with a Range

To print a range of lines from 'a' to 'b', you can use:

tail -n +a file.txt | head -n b

`'tail -n +a'` prints lines from 'a' to EOF. Pipe (`|`) is used to feed the output into `head`, which prints the first 'b' lines from the input.

In conclusion, copying from a specific line number to the end of a file in Linux can be achieved using both `sed` and `tail`. Choose the method that best fits your workflow. Happy coding!