【问题标题】:ls: how to display directory + filename on each linels:如何在每一行显示目录+文件名
【发布时间】:2013-03-14 22:01:46
【问题描述】:

我有一个包含很多子目录的目录,我想在每一行列出所有带有特定扩展名的文件,包括它们所在的(子)目录。我现在正在使用:

ls /home/directory -R | grep ".ext" > files.txt

这并没有给我我正在寻找的输出...... 理想情况下,我想要一个看起来像这样的输出:

/home/directory/subdirectory1/file1.ext               4.3Mb
/home/directory/subdirectory1/subsubdir1/file2.ext    3.3Mb
/home/directory/subdirectory2/file3.ext               4.6Mb
/home/directory/subdirectory3/file4.ext               5.2Mb
... etc

或者甚至更好,将目录和文件名放在不同的列中:

/home/directory/subdirectory1/               file1.ext    4.3Mb
/home/directory/subdirectory1/subsubdir1/    file2.ext    3.3Mb
/home/directory/subdirectory2/               file3.ext    4.6Mb
/home/directory/subdirectory3/               file4.ext    5.2Mb
... etc

关于如何做到这一点的任何想法?非常感谢!

【问题讨论】:

  • 看起来你想得到du的输出...

标签: bash unix ls


【解决方案1】:

find putty -type f -name '*.c' -printf "%h\t%f\t%s\n" | column -t

会产生这样的东西

putty          sshzlib.c   38615
putty          notiming.c  584
putty/charset  macenc.c    7129
putty/charset  sbcs.c      1190

如果您想要整个路径,请将您的目录参数显示为从根目录开始的绝对目录路径。

【讨论】:

    猜你喜欢
    • 2018-09-11
    • 2016-06-18
    • 2019-08-08
    • 2021-10-24
    • 1970-01-01
    • 2015-02-23
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多