Limit output of all Linux commands

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.

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.

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?


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

  • hardlink a copy to the existing utility
  • write a tiny bash function that calls the utility and pipes to head (or wc, or whatever)
  • alias the name of the utility to call your function.

So along these lines (utterly untested):

$ ln `which cat` ~/bin/old_cat

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

alias cat=trunc_cat

Need Your Help

Php header refresh not working on chrome

php google-chrome header

I have a php script that outputs a confirmation text and redirects using header to a certain page after i log in. The script is working fine on mozilla and internet explorer but fails to redirect m...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.