Omitting the first line from any Linux command output

Linux

Linux Problem Overview


I have a requirement where i'd like to omit the 1st line from the output of ls -latr "some path" Since I need to remove total 136 from the below output

enter image description here

So I wrote ls -latr /home/kjatin1/DT_901_linux//autoInclude/system | tail -q which excluded the 1st line, but when the folder is empty it does not omit it. Please tell me how to omit 1st line in any linux command output

Linux Solutions


Solution 1 - Linux

The tail program can do this:

ls -lart | tail -n +2

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

Solution 2 - Linux

Pipe it to awk:

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

or sed

sed -n '1!p'

Solution 3 - Linux

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

Solution 4 - Linux

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.

Solution 5 - Linux

You can use awk command:

For command output use pipe: | awk 'NR>1'

For output of file: awk 'NR>1' file.csv

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAabinGunzView Question on Stackoverflow
Solution 1 - LinuxDonal FellowsView Answer on Stackoverflow
Solution 2 - LinuxFredrik PihlView Answer on Stackoverflow
Solution 3 - LinuxJeff FerlandView Answer on Stackoverflow
Solution 4 - Linux逆さまView Answer on Stackoverflow
Solution 5 - LinuxYakir GIladi EdryView Answer on Stackoverflow