遍历目录及其子目录中的所有文件
使用Shell遍历目录及其子目录中的所有文件方法_linux shell_脚本之家
$ vi traveDir.sh
#! /bin/bash
function read_dir(){
for file in `ls $1` #注意此处这是两个反引号,表示运行系统命令
do
if [ -d $1"/"$file ] #注意此处之间一定要加上空格,否则会报错
then
read_dir $1"/"$file
else
echo $1"/"$file #在此处处理文件即可
fi
done
}
#读取第一个参数
read_dir $1
判断文件是否有修改
# #!/bin/bash
startdate=`date +'%Y%m%d'`
starttime=`date +'%Y-%m-%d %H:%M:%S'`
echo "------------------------------------------------------------算法开始------------------------------------------------------------------" >> /home/2021/ab/shell/log/$startdate.logFILE1='/home/2021/ab/flag/002flag.txt'
last_time1=$(stat -c %Y $FILE1)sudo sh /home/2021/ab/shell/000.sh
FILE2='/home/2021/ab/flag/002flag.txt'
last_time2=$(stat -c %Y $FILE2)if [ $last_time1 = $last_time2 ]
then
echo "没有新数据" >> /home/2021/ab/shell/log/$startdate.logelse
cat /home/2021/ab/flag/002flag.txt | while read line
do
echo "运行的数据是:"$line >> /home/2021/ab/shell/log/$startdate.log
donesudo python3 /home/2021/ab_to_z/sendmysql.py
sudo sh /home/2021/ab/shell/001.sh
sudo sh /home/2021/ab/shell/002.sh
sudo sh /home/2021/ab/shell/003.sh
sudo sh /home/2021/ab/shell/004.sh
sudo sh /home/2021/ab/shell/005.sh
sudo sh /home/2021/ab/shell/006.sh
sudo sh /home/2021/ab/shell/007.sh
fiendtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "总计运行时间: "$((end_seconds-start_seconds))"s">> /home/2021/ab/shell/log/$startdate.log
echo "------------------------------------------------------------算法结束------------------------------------------------------------------">> /home/2021/ab/shell/log/$startdate.log