Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omitting the first line from any Linux command output

Tags:

linux

People also ask

How do I ignore the first line in Linux?

The first line of a file can be skipped by using various Linux commands. As shown in this tutorial, there are different ways to skip the first line of a file by using the `awk` command. Noteably, the NR variable of the `awk` command can be used to skip the first line of any file.

How do you skip a line in Linux?

Using head to get the first lines of a stream, and tail to get the last lines in a stream is intuitive. But if you need to skip the first few lines of a stream, then you use tail “-n +k” syntax. And to skip the last lines of a stream head “-n -k” syntax.

How do you skip a line in terminal?

If you don't want to use echo repeatedly to create new lines in your shell script, then you can use the \n character. The \n is a newline character for Unix-based systems; it helps to push the commands that come after it onto a new line.


The tail program can do this:

ls -lart | tail -n +2

The -n +2 means “start passing through on the second line of output”.


Pipe it to awk:

awk '{if(NR>1)print}'

or sed

sed -n '1!p'

ls -lart | tail -n +2 #argument means starting with line 2

This is a quick hacky way: ls -lart | grep -v ^total.

Basically, remove any lines that start with "total", which in ls output should only be the first line.

A more general way (for anything):

ls -lart | sed "1 d"

sed "1 d" means only print everything but first line.