面试题答案
一键面试#!/bin/bash
# 检查并创建 /data/logs 目录
if [ ! -d "/data/logs" ]; then
mkdir /data/logs
fi
# 移动.log文件并记录结果
for file in /data/*.log; do
if [ -f "$file" ]; then
mv "$file" /data/logs 2>/data/error_logs.txt
if [ $? -eq 0 ]; then
echo "$file" >> /data/moved_logs.txt
fi
fi
done