-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.sh
More file actions
55 lines (40 loc) · 1.23 KB
/
read.sh
File metadata and controls
55 lines (40 loc) · 1.23 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
52
53
54
55
#!/bin/bash
# 读取文件函数
# 参数1:文件路径
# 参数2:是否启用间隔(true/false)
# 参数3:间隔秒数(可选,默认1秒)
read_file() {
local file="$1"
local with_delay="$2"
local delay=${3:-1}
echo " [*] Reading file: $file"
cat "$file" > /dev/null
if [ "$with_delay" == "true" ]; then
sleep "$delay"
fi
}
# 示例用法:
# read_file "/path/to/file.txt" true 2 # 读文件,间隔2秒
# read_file "/path/to/file.txt" false # 读文件,无间隔
# ------------主流程--------------
total_reads=0
target_reads=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_reads" -ge "$target_reads" ]; 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_reads" -ge "$target_reads" ]; then
break 2
fi
read_file "$file" "$with_delay" "$delay_seconds"
total_reads=$((total_reads + 1))
done
done
echo "[+] Total read operations done: $total_reads"