How to automatically pipe to less if the result is more than a page on my shell?

前端 未结 5 669
梦如初夏
梦如初夏 2021-02-01 03:41

Mostly, I will not use | less for each and every command from the shell.

Pipe to less is used only when I actually run the command without is and find out t

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 04:14

    I wrote this wrapper function and put it in my .profile. You can use this before a command and it will automatically pipe it to less if it is longer than 1 page.

    lcmd ()
    {
        echo "$("$@")" | less -F;
    };
    

    So 'lcmd ls' would ls the current directory and pipe that output to less.

提交回复
热议问题