gIrl1990
V2EX  ›  问与答

mac 哪个是 more 命令?怎么写,怎么 limit 每次输出行数?

  •  
  •   gIrl1990 · Aug 29, 2019 · 2949 views
    This topic created in 2626 days ago, the information mentioned may be changed or developed.

    wiki/More_(command)

    more [options] [file_name]
    -num: This option specifies an integer which is the screen size (in lines).
    
    Supplement 1  ·  Aug 29, 2019

    哦,原来参数写错了,我是说macos里执行more -2 怎么无效

    MacOS里面执行

    > man more
    less - opposite of more
    
           -n or --line-numbers
    Suppresses line numbers.  The default (to use line numbers) may cause less to run more slowly in some cases, especially with a very large input file.  Suppressing line numbers with the -n option will avoid this problem.  Using line numbers means: the line number will be dis played  in  the verbose prompt and in the = command, and the v command will pass the current line number to the editor (see also the dis cussion of LESSEDIT in PROMPTS below).
    
    > more -n 3 long.txt
    # 每次输出2行, 怎么少了1行?
    

    Linux 里

    > man more
    more - file perusal filter for crt viewing
    
           -number
    The screen size to use, in number of lines.
    
    > more -3 long.txt
    # 每次输出3行
    
    Supplement 2  ·  Aug 29, 2019

    但 -n or --line-numbers 的描述看起来不是限制每次输出行数啊。

    那段英文到底什么意思啊

    12 replies  •  2019-08-31 14:13:18 +08:00
    azh7138m
    azh7138m
    Aug 29, 2019
    1
    less
    Less is a program similar to more (1)
    gIrl1990
    gIrl1990
    OP
    Aug 29, 2019
    2
    @azh7138m 想要那种每次输出一部分在终端里面,而不是
    cat 输出全部
    less 0 输出
    head 输出头部但不能续读
    misaka19000
    misaka19000
    Aug 29, 2019
    3
    less is more
    sleepm
    sleepm
    Aug 29, 2019 via Android
    4
    写的很清楚了,more -num filename
    再举个例子 rm -rf / 一般我们写 rm / -rf 但是在 mac 中 -rf 会被当成文件
    azh7138m
    azh7138m
    Aug 29, 2019
    5
    这个需求是 split
    shell 循环读输出就行
    gIrl1990
    gIrl1990
    OP
    Aug 29, 2019
    6
    @sleepm 你好像没理解我意思,我 APPEND 了再看看
    @azh7138m 我 APPEND 了再看看
    azh7138m
    azh7138m
    Aug 29, 2019
    7
    我觉得是个 X-Y PROBLEM
    https://coolshell.cn/articles/10804.html
    gIrl1990
    gIrl1990
    OP
    Aug 29, 2019
    8
    @azh7138m 不对吧,split 会产生文件,不是我想要的
    azh7138m
    azh7138m
    Aug 29, 2019
    9
    如果你坚持用 shell 处理,直接读入数组,每一项就是一行
    我还是觉得是个 X-Y PROBLEM
    为了一个不存在的问题,在反复 hack
    jmc891205
    jmc891205
    Aug 29, 2019
    10
    less 没有你想要的功能
    gIrl1990
    gIrl1990
    OP
    Aug 30, 2019
    11
    MacOS:
    ```bash
    > gsha1sum /usr/bin/more /usr/bin/less
    6f6ec068da5870eb28b04d0cc50abc5ec5e4b85e /usr/bin/more
    6f6ec068da5870eb28b04d0cc50abc5ec5e4b85e /usr/bin/less
    # 这两个是同一个文件?
    > more --version
    less 487 (POSIX regular expressions)
    Copyright (C) 1984-2016 Mark Nudelman

    less comes with NO WARRANTY, to the extent permitted by law.
    For information about the terms of redistribution,
    see the file named README in the less distribution.
    Homepage: http://www.greenwoodsoftware.com/less
    > more -n 3 long.txt
    # 可以实现 linux 里 more 的效果
    > less -n 3 long.txt
    # 既然是同样文件,为何出错?
    ```
    那如果他们不同,从 Homepage 下载到的源码如何编译出 more 命令?
    gIrl1990
    gIrl1990
    OP
    Aug 31, 2019
    12
    See: https://github.com/gwsw/less/issues/23
    ```bash
    more -n 3 long.txt
    more -n3 long.txt
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   913 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:18 · PVG 04:18 · LAX 12:18 · JFK 15:18
    ♥ Do have faith in what you're doing.