Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
yfnok
V2EX  ›  Linux

请问下 Linux 高手, shell 脚本如何按照时间排序,获取文件夹里的文件列表呢

  •  
  •   yfnok · Mar 16, 2022 · 2607 views
    This topic created in 1716 days ago, the information mentioned may be changed or developed.

    我搜了个例子,但是没按照时间排序,请问如何加上时间排序呢

    多谢多谢

    #!/bin/bash

    get all filename in specified path

    search_dir=/root/download for entry in "$search_dir"/* do echo "$entry"

    done

    7 replies  •  2022-03-16 13:06:01 +08:00
    tomychen
    tomychen
    Mar 16, 2022
    1
    ls -altr ?
    skiy
    skiy
    Mar 16, 2022 via iPhone
    2
    man ls 应该可以找到案例吧?
    id4alex
    id4alex
    Mar 16, 2022
    3
    ```
    for i in `ls -at`
    do
    echo $i
    done
    ```
    wenzhonghu
    wenzhonghu
    Mar 16, 2022
    4
    ls -t
    要倒序的话 ls -tr
    wenzhonghu
    wenzhonghu
    Mar 16, 2022
    5
    knightdf
    knightdf
    Mar 16, 2022
    6
    `ls -c`
    huntagain2008
    huntagain2008
    Mar 16, 2022
    7
    本人小白,最近看 1983 年的《 UNIX 环境编程》刚好看到 ls 命令的选项 t 是按修改时间排序,新的文件在前。
    $ ls -t
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3873 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:43 · PVG 13:43 · LAX 21:43 · JFK 00:43
    ♥ Do have faith in what you're doing.