bash - 使用 Bash 在目录中查找最近的文件
问题描述
我想编写一个 Bash 脚本在文件夹中查找新文件(最近添加的文件)并将新文件的名称(包括文件类型,即 example.png)输出到变量。
我该怎么做?
解决方案
可能您想使用以下-t
选项ls
:
ls -t
来自man ls
:
--sort=WORD
sort by WORD instead of name: none (-U), size (-S), time
(-t), version (-v), extension (-X)
--time=WORD
change the default of using modification times; access
time (-u): atime, access, use; change time (-c): ctime,
status; birth time: birth, creation;
with -l, WORD determines which time to show; with
--sort=time, sort by WORD (newest first)
--time-style=TIME_STYLE
time/date format with -l; see TIME_STYLE below
-t sort by time, newest first; see --time
推荐阅读
- angular - provideIn:在库中复制的“根”服务
- python - 如何将基于类的视图的上下文传递给 Django 中的模板?
- debugging - 什么定义了 Cloud Run 容器实例日志的日志类型(默认、警报、错误、关键等)?
- keras - 使用 RNN,我们如何预测货币价格以在给定时间段内达到特定价格?
- python - 如何使用 AutoKeras 获得可重现的结果
- java - 当我使用 Intents for Android Studio 时,我没有弹出“包上下文”
- c - 变量的地址存储在内存中的什么位置?
- javascript - 如何获取所需的机器列数据?
- prolog - <> 在序言中是什么意思?
- c - C 中函数返回的隐式强制转换以及 Visual Studio 不抛出警告的原因