List files by last edited date

前端 未结 4 2142
时光说笑
时光说笑 2020-12-07 13:31

I have a directory: /home/user/

How can I list every file in this directory (including those in sub directories) and order them by the date that they we

4条回答
  •  旧巷少年郎
    2020-12-07 14:04

    For zsh users, you could also use glob qualifiers (also documented on man zshexpn):

    echo *(om)
    

    Where o stands for sort order, up and m stands for last modification time.

    This can be useful when used in a for loop or another command:

    for file in *(^om); do
      [ -e "$file" ] || continue
      # do something with file orderer from least recently modified to last modified
    done
    

    Or chained with another glob qualifier:

    last_modified_file=(*(om[1]))
    

提交回复
热议问题