Advertisement
Advertisement


Omitting the first line from any Linux command output


Question

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

2011/09/06
1
169
9/6/2011 10:48:08 AM

Accepted Answer

Pipe it to awk:

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

or sed

sed -n '1!p'
2011/09/06
188
9/6/2011 10:37:35 AM


ls -lart | tail -n +2 #argument means starting with line 2
2011/09/06

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.

2011/09/06

Source: https://stackoverflow.com/questions/7318497
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]