限制所有Linux命令的输出 [英] Limit output of all Linux commands

查看:199
本文介绍了限制所有Linux命令的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来限制Linux中所有命令行程序产生的输出量,并且最好告诉我何时受到限制.

I'm looking for a way to limit the amount of output produced by all command line programs in Linux, and preferably tell me when it is limited.

我正在处理一台显示滞后的服务器.有时,我会不小心运行一个命令,该命令会向终端输出大量文本,例如大文件上的cat或包含许多文件的目录上的ls.然后,我必须等待一段时间才能将所有输出打印到终端上.

I'm working over a server which has a lag on the display. Occasionally I will accidentally run a command which outputs a large amount of text to the terminal, such as cat on a large file or ls on a directory with many files. I then have to wait a while for all the output to be printed to the terminal.

那么有没有一种方法可以自动将所有输出传送到headwc之类的命令中,以防止必须将过多的输出打印到终端上?

So is there a way to automatically pipe all output into a command like head or wc to prevent too much output having to be printed to terminal?

推荐答案

我不了解一般情况,但是对于每个众所周知的命令(cat,ls,find?) 您可以执行以下操作:

I don't know about the general case, but for each well-known command (cat, ls, find?) you could do the following:

  • 将副本硬链接到现有实用程序
  • 编写一个小的bash函数,调用该实用程序并通过管道将其发送到head(或wc,或其他任何东西)
  • 为用来调用您的函数的实用程序名称的别名.

因此遵循这些原则(完全未经测试):

So along these lines (utterly untested):

$ ln `which cat` ~/bin/old_cat

function trunc_cat () {
   `old_cat $@ | head -n 100`
}

alias cat=trunc_cat

这篇关于限制所有Linux命令的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆