V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
gIrl1990
V2EX  ›  问与答

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

  •  
  •   gIrl1990 · 2019-08-29 18:29:25 +08:00 · 1927 次点击
    这是一个创建于 1703 天前的主题,其中的信息可能已经有所发展或是发生改变。

    wiki/More_(command)

    more [options] [file_name]
    -num: This option specifies an integer which is the screen size (in lines).
    
    第 1 条附言  ·  2019-08-29 20:06:05 +08:00

    哦,原来参数写错了,我是说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行
    
    第 2 条附言  ·  2019-08-29 20:12:00 +08:00

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

    那段英文到底什么意思啊

    12 条回复    2019-08-31 14:13:18 +08:00
    azh7138m
        1
    azh7138m  
       2019-08-29 18:49:17 +08:00
    less
    Less is a program similar to more (1)
    gIrl1990
        2
    gIrl1990  
    OP
       2019-08-29 18:57:41 +08:00
    @azh7138m 想要那种每次输出一部分在终端里面,而不是
    cat 输出全部
    less 0 输出
    head 输出头部但不能续读
    misaka19000
        3
    misaka19000  
       2019-08-29 19:27:43 +08:00
    less is more
    sleepm
        4
    sleepm  
       2019-08-29 19:37:35 +08:00 via Android
    写的很清楚了,more -num filename
    再举个例子 rm -rf / 一般我们写 rm / -rf 但是在 mac 中 -rf 会被当成文件
    azh7138m
        5
    azh7138m  
       2019-08-29 19:50:00 +08:00
    这个需求是 split
    shell 循环读输出就行
    gIrl1990
        6
    gIrl1990  
    OP
       2019-08-29 20:13:23 +08:00
    @sleepm 你好像没理解我意思,我 APPEND 了再看看
    @azh7138m 我 APPEND 了再看看
    azh7138m
        7
    azh7138m  
       2019-08-29 20:39:20 +08:00
    我觉得是个 X-Y PROBLEM
    https://coolshell.cn/articles/10804.html
    gIrl1990
        8
    gIrl1990  
    OP
       2019-08-29 20:48:54 +08:00
    @azh7138m 不对吧,split 会产生文件,不是我想要的
    azh7138m
        9
    azh7138m  
       2019-08-29 20:57:03 +08:00
    如果你坚持用 shell 处理,直接读入数组,每一项就是一行
    我还是觉得是个 X-Y PROBLEM
    为了一个不存在的问题,在反复 hack
    jmc891205
        10
    jmc891205  
       2019-08-29 21:20:48 +08:00
    less 没有你想要的功能
    gIrl1990
        11
    gIrl1990  
    OP
       2019-08-30 10:15:51 +08:00
    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
        12
    gIrl1990  
    OP
       2019-08-31 14:13:18 +08:00
    See: https://github.com/gwsw/less/issues/23
    ```bash
    more -n 3 long.txt
    more -n3 long.txt
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2697 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 11:07 · PVG 19:07 · LAX 04:07 · JFK 07:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.