批量解压缩文件的脚本
#!/bin/bash
# 批量解压缩脚本
# 检查是否有足够的权限执行脚本
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# 定义目标目录
target_dir="/lamp"
# 进入目标目录
cd "$target_dir" || exit 1
# 检查是否存在压缩文件
if ! ls *.tar.gz &>/dev/null; then
echo "No .tar.gz files found in $target_dir"
exit 1
fi
# 解压缩所有 .tar.gz 文件
for file in *.tar.gz; do
echo "Extracting $file..."
tar -zxf "$file" -C "$target_dir" &>/dev/null
done
# 删除临时文件
rm -f "$target_dir"/ls.log
echo "Extraction completed."