在 Bash 中,我如何获取某个日期的用户输入,然后搜索为该日期创建的文件?

In Bash, how do I get user input for a date, and then search for files created for that date?

我想做的是将 find type -f 与 newermt 选项一起使用,但后来我意识到我需要提前一天才能得到我的结果,这就是我被困的地方。例如:

find . -type f -newermt 20150505 -newermt 20150506

效果很好,所以我打算让用户输入日期。所以:

/myscript.sh 20150505

但问题是,我必须将用户输入日期提前一天,这看起来一团糟(原因很明显)。此外,让用户输入两个日期来调用此脚本也是不受欢迎的。有人可以提供更好的解决方案,或者也许有一种方法可以将他们的输入转换为实际日期,让 linux 提前一天以便有意义吗?

您可以使用 GNU date 提前日期:

currentday=   # If this is 20150505, then ...
nextday=$(date +%Y%m%d --date "$currentday +1 day") # ... this is 20150506