#!/bin/bash
# 定义目标目录
TARGET_DIR="/path/to/your/directory"
# 检查目录是否存在
if [ ! -d "$TARGET_DIR" ]; then
echo "Directory does not exist!"
exit 1
fi
# 进入目标目录
cd "$TARGET_DIR"
# 批量修改文件名,例如将所有 .txt 文件的扩展名改为 .md
for file in *.txt; do
if [ -e "$file" ]; then
mv "$file" "${file%.txt}.md"
fi
done
echo "File renaming completed."
TARGET_DIR="/path/to/your/directory" 设置要操作的文件夹路径。if [ ! -d "$TARGET_DIR" ] 判断目录是否存在,如果不存在则输出提示信息并退出脚本。cd "$TARGET_DIR" 进入指定的目录。for file in *.txt 遍历所有 .txt 文件,并通过 mv "$file" "${file%.txt}.md" 将其重命名为 .md 文件。你可以根据需要修改文件名规则或扩展名。
上一篇:linux怎么看内存被谁占用了
下一篇:查看文件权限的linux命令
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站