Coder Perfect

Omitting the first line from any Linux command output

Problem

I need to remove the first line from the output of ls -latr “some path” for a requirement. Because I need to eliminate total 136 from the result below,

1 linux/autoInclude/system | tail -q omitted the first line, but it does not omit it when the folder is empty. Please instruct me on how to remove the first line from any linux command output.

Asked by AabinGunz

Solution #1

This is something the tail program can do:

ls -lart | tail -n +2

“Start passing through on the second line of output,” says the -n +2.

Answered by Donal Fellows

Solution #2

It’ll be piped to awk:

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

or sed

sed -n '1!p'

Answered by Fredrik Pihl

Solution #3

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

Answered by Jeff Ferland

Solution #4

ls -lart | grep -v total is a quick hacky technique.

Basically, eliminate any lines that begin with “total,” which should only be the first line in ls output.

A more generic approach (for anything) is as follows:

sed “1 d” | ls -lart

sed “1 d” specifies that only the first line should be printed.

Answered by 逆さま

Solution #5

You can use the awk command to do this:

| awk ‘NR>1’ | awk ‘NR>1’ | awk ‘NR>1’ | awk ‘NR

awk ‘NR>1’ file.csv awk ‘NR>1’ awk ‘NR>1’ awk ‘NR>1’ a

Answered by Yakir GIladi Edry

Post is based on https://stackoverflow.com/questions/7318497/omitting-the-first-line-from-any-linux-command-output