这个脚本运行以后,等于制定时间的也算进去了,我只要大于指定时间的
时间: 2024-03-10 22:50:04 浏览: 28
如果您只想查找修改时间晚于指定日期的文件,可以将 -newermt 参数改为 -newer 参数,同时将指定日期的时间戳加上一天,以保证查找到的文件修改时间晚于指定日期的文件。
修改后的脚本如下:
```
#!/bin/bash
# 输入目录路径和指定日期
read -p "请输入目录路径:" dir_path
read -p "请输入指定日期(格式:YYYY-MM-DD):" target_date
# 将指定日期转换为 Unix 时间戳,并加上一天
target_timestamp=$(date -d "$target_date +1 day" +%s)
# 在指定目录下查找文件,并排序
matched_file=$(find "$dir_path" -type f -newer "$target_timestamp" -printf "%T@ %p\n" | sort -n | head -n 1)
# 判断是否找到匹配的文件
if [[ -z "$matched_file" ]]; then
echo "没找到"
else
# 输出时间最早的文件
matched_file_path=$(echo "$matched_file" | cut -d ' ' -f 2)
echo "找到文件:$matched_file_path"
fi
```
这样,就只会查找到修改时间晚于指定日期的文件了。
相关问题
我希望关闭这个脚本之后再运行另一个脚本,python 实现
您可以使用 Python 的 subprocess 模块来实现这一功能。您可以使用以下代码关闭当前脚本并启动另一个脚本:
```
import subprocess
import sys
subprocess.Popen([sys.executable, 'path/to/another/script.py'])
sys.exit()
```
其中,'path/to/another/script.py' 是您要运行的另一个脚本的路径。该代码将启动另一个 Python 解释器并运行另一个脚本,等待另一个脚本完成后关闭当前脚本。
java redis集群 lua脚本获取系统时间是否可以指定运行的节点
在Redis集群中,Lua脚本是在执行脚本的那个节点上执行的,无法直接指定运行的节点。但是,我们可以通过自定义分片算法,将相同的键映射到同一个节点上,从而实现脚本在指定节点上执行。
对于获取系统时间的Lua脚本,在Redis中可以使用内置的time()函数来获取当前时间。例如,以下脚本可以返回当前时间戳:
```
return redis.call('time')[1]
```
如果要让该脚本在指定节点上执行,可以使用自定义分片算法将相同的键映射到该节点上。例如,可以使用JedisCluster的setSlot()方法将键“time”映射到指定的节点上,然后再执行Lua脚本。示例如下:
```
JedisCluster jedisCluster = new JedisCluster(nodes, config);
String script = "return redis.call('time')[1]";
String key = "time";
int slot = JedisClusterCRC16.getSlot(key);
jedisCluster.setSlot(key, slot);
String result = jedisCluster.eval(script, 0, key).toString();
```
在这个例子中,我们使用JedisClusterCRC16的getSlot()方法获取键“time”对应的槽号,然后使用setSlot()方法将键“time”映射到指定的节点上。最后,我们使用eval()方法执行Lua脚本,并指定需要执行脚本的键。
需要注意的是,在使用自定义分片算法时,需要保证相同的键映射到同一个节点上执行,否则会导致脚本执行结果不一致的问题。同时,由于时间戳是与具体时间无关的相对值,因此在不同节点上执行脚本得到的时间戳可能会有微小的误差。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)