【问题标题】:get a 3-column list of file names in the present working directory Linux command line获取当前工作目录 Linux 命令行中文件名的 3 列列表
【发布时间】:2021-07-28 13:50:40
【问题描述】:

获取当前工作目录 Linux 命令行中文件名的 3 列列表

我知道如何像ls -3 一样进入列,但是当我尝试获取 3 列时它不起作用,是否可以获取 3 列?

【问题讨论】:

    标签: linux terminal linux-mint


    【解决方案1】:

    很遗憾,ls 不支持这个。您的ls 输出必须通过管道传输。如果您知道分隔符是什么,可以使用sedcut 等程序对数据进行排序。在列间距方面,最常见的分隔符是制表符。

    您也可以根据您的屏幕大小使用ls -wn 将 n 替换为整数, 根据您的终端大小,这几乎可以很好地工作,您也可以使用stty size 获取终端大小并根据您想要的输出计算您的值。

    $ stty size | cut -d" " -f1   #height
     36  #sample_output
    
    $ stty size | cut -d" " -f2   #width
     78  #sample_output
    
    $ ls -w90  #works fine for 36*78
    

    或者你可以使用 xargs

    $ ls | xargs -n 3 #list files in three column
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 2012-04-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      相关资源
      最近更新 更多