-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite.sh
More file actions
51 lines (37 loc) · 1.11 KB
/
write.sh
File metadata and controls
51 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# 写入文件函数
# 参数1:文件路径
# 参数2:是否启用间隔(true/false)
# 参数3:间隔秒数(默认1秒)
write_file() {
local file="$1"
local with_delay="$2"
local delay=${3:-1}
echo " [*] Writing to file: $file"
echo "Modified on $(date)" >> "$file"
if [ "$with_delay" == "true" ]; then
sleep "$delay"
fi
}
# ------------主流程--------------
total_writes=0
target_writes=10
with_delay=false # 是否启用间隔写入
delay_seconds=1 # 写入间隔秒数
# 找所有以 zzz 开头的目录,放数组
mapfile -t folders < <(find / -type d -name "zzz*" 2>/dev/null)
for folder in "${folders[@]}"; do
if [ "$total_writes" -ge "$target_writes" ]; then
break
fi
echo "[+] Processing folder: $folder"
mapfile -t files < <(find "$folder" -maxdepth 1 -type f 2>/dev/null)
for file in "${files[@]}"; do
if [ "$total_writes" -ge "$target_writes" ]; then
break 2
fi
write_file "$file" "$with_delay" "$delay_seconds"
total_writes=$((total_writes + 1))
done
done
echo "[+] Total write operations done: $total_writes"