从任何 Linux 命令输出中省略第一行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7318497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:02:25  来源:igfitidea点击:

Omitting the first line from any Linux command output

linux

提问by AabinGunz

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 136from the below output

我有一个要求,我想从输出中省略第一行,ls -latr "some path"因为我需要total 136从下面的输出中删除

enter image description here

在此处输入图片说明

So I wrote ls -latr /home/kjatin1/DT_901_linux//autoInclude/system | tail -qwhich 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

所以我写了ls -latr /home/kjatin1/DT_901_linux//autoInclude/system | tail -q其中排除了第一行,但是当文件夹为空时它不会省略它。请告诉我如何在任何 linux 命令输出中省略第一行

采纳答案by Fredrik Pihl

Pipe it to awk:

管道它到awk

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

or sed

或者 sed

sed -n '1!p'

回答by wkl

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

这是一种快速的hacky方式:ls -lart | grep -v ^total.

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

基本上,删除所有以“total”开头的行,它在ls输出中应该只是第一行。

A more general way (for anything):

更通用的方式(对于任何事情):

ls -lart | sed "1 d"

ls -lart | sed "1 d"

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

sed "1 d"意味着只打印除第一行之外的所有内容。

回答by Donal Fellows

The tailprogram can do this:

tail程序可以这样做:

ls -lart | tail -n +2

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

-n +2装置“开始穿过上输出的第二行”。

回答by Jeff Ferland

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