Linux 如何使用“tail -1 */filename”拖尾多个文件的最后一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10353912/
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
How to tail the last line of multiple files using "tail -1 */filename"
提问by mrkent
tail */filename
works, but
有效,但是
tail -1 */filename
doesn't. Why is this? And is there a 1 liner to perform this task without loops?
没有。为什么是这样?是否有 1 个班轮可以在没有循环的情况下执行此任务?
head -1 */filename
works for some strange reason.
出于某种奇怪的原因工作。
采纳答案by Casper
While head
works with -1
on multiple files, tail
does not. But it works with the -n
argument instead:
虽然head
适用-1
于多个文件,tail
但不会。但它适用于-n
参数:
tail -n 1 */filename
回答by srinivas Davuluri
If you are still looking for answer please try below one :
如果您仍在寻找答案,请尝试以下之一:
Go to the directory in which file are available and execute below command
转到文件可用的目录并执行以下命令
ls -1|while read file; do tail -1 $file; done