Browse Source

Updated files

master
adiao 3 years ago
parent
commit
5221703cca
  1. 158
      数据结构.md

158
数据结构.md

@ -23,161 +23,3 @@ void test(){ @@ -23,161 +23,3 @@ void test(){
---
以下是一个可以每隔一分钟检查是否有文件更新和创建的shell脚本:
```
Copy code
#!/bin/bash
# 将 <dir> 替换为你想要监控文件的目录
# 将 <command> 替换为你想要执行的命令
# 初始化文件列表
OLD_FILES=`ls -l <dir>`
while true
do
# 等待 60 秒
sleep 60
# 获取当前文件列表
NEW_FILES=`ls -l <dir>`
# 检查文件是否相同
if [ "$OLD_FILES" != "$NEW_FILES" ]; then
# 文件有更新或创建,执行你想要执行的命令
<command>
# 更新文件列表
OLD_FILES=$NEW_FILES
fi
done
```
使用方法:
1. 将 <dir> 替换为你想要监控文件的目录;
2. 将 <command> 替换为你想要执行的命令(例如,发送一个通知或者备份文件);
3. 保存为一个 .sh 文件;
4. 运行 `chmod +x <filename>.sh`,给脚本添加执行权限;
5. 运行 `./<filename>.sh` 开始监控文件。
我需要一个可以每隔一分钟检查文件内容是否有更新并且检查是否有新的文件创建的shell脚本
以下是一个可以每隔一分钟检查文件内容是否有更新、检查是否有新的文件创建的shell脚本:
```
Copy code
#!/bin/bash
# 将 <dir> 替换为你想要监控文件的目录
# 将 <command> 替换为你想要执行的命令
# 初始化文件列表
OLD_FILE_CHECKSUMS=`find <dir> -type f -exec md5sum {} \;`
OLD_FILES=`find <dir> -type f`
while true
do
# 等待 60 秒
sleep 60
# 获取当前文件列表和文件内容的 checksum
NEW_FILE_CHECKSUMS=`find <dir> -type f -exec md5sum {} \;`
NEW_FILES=`find <dir> -type f`
# 检查文件列表是否相同
if [ "$OLD_FILES" != "$NEW_FILES" ]; then
# 文件有更新或创建,执行你想要执行的命令
<command>
# 更新文件列表和 checksums
OLD_FILE_CHECKSUMS=$NEW_FILE_CHECKSUMS
OLD_FILES=$NEW_FILES
# 如果文件列表和 checksums 相同,则检查文件内容是否有更新
elif [ "$OLD_FILE_CHECKSUMS" != "$NEW_FILE_CHECKSUMS" ]; then
# 文件内容有更新,执行你想要执行的命令
<command>
# 更新文件 checksums
OLD_FILE_CHECKSUMS=$NEW_FILE_CHECKSUMS
fi
done
```
使用方法:
1. 将 <dir> 替换为你想要监控文件的目录;
2. 将 <command> 替换为你想要执行的命令(例如,发送一个通知或者备份文件);
3. 保存为一个 .sh 文件;
4. 运行 `chmod +x <filename>.sh`,给脚本添加执行权限;
5. 运行 `./<filename>.sh` 开始监控文件。
我需要一个可以每隔一分钟检查Markdown文件内容是否有更新并且检查是否有新的Markdown文件创建的shell脚本
以下是一个可以每隔一分钟检查Markdown文件内容是否有更新、检查是否有新的Markdown文件创建的shell脚本:
```
Copy code
#!/bin/bash
# 将 <dir> 替换为你想要监控文件的目录
# 将 <command> 替换为你想要执行的命令
# 初始化文件列表
OLD_FILE_CHECKSUMS=`find <dir> -type f -name "*.md" -exec md5sum {} \;`
OLD_FILES=`find <dir> -type f -name "*.md"`
while true
do
# 等待 60 秒
sleep 60
# 获取当前文件列表和文件内容的 checksum
NEW_FILE_CHECKSUMS=`find <dir> -type f -name "*.md" -exec md5sum {} \;`
NEW_FILES=`find <dir> -type f -name "*.md"`
# 检查文件列表是否相同
if [ "$OLD_FILES" != "$NEW_FILES" ]; then
# 文件有更新或创建,执行你想要执行的命令
<command>
# 更新文件列表和 checksums
OLD_FILE_CHECKSUMS=$NEW_FILE_CHECKSUMS
OLD_FILES=$NEW_FILES
# 如果文件列表和 checksums 相同,则检查文件内容是否有更新
elif [ "$OLD_FILE_CHECKSUMS" != "$NEW_FILE_CHECKSUMS" ]; then
# 文件内容有更新,执行你想要执行的命令
<command>
# 更新文件 checksums
OLD_FILE_CHECKSUMS=$NEW_FILE_CHECKSUMS
fi
done
```
使用方法:
1. 将 <dir> 替换为你想要监控文件的目录;
2. 将 <command> 替换为你想要执行的命令(例如,发送一个通知或者备份文件);
3. 保存为一个 .sh 文件;
4. 运行 `chmod +x <filename>.sh`,给脚本添加执行权限;
5. 运行 `./<filename>.sh` 开始监控Markdown文件。
Ssss sssss
sss
ssssssssSsssss

Loading…
Cancel
Save