Limit output of all Linux commands

前端 未结 5 1106
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 19:23

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 s

5条回答
  •  醉梦人生
    2021-01-18 20:11

    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
    

提交回复
热议问题