note/ren.sh
2025-11-19 10:16:05 +08:00

19 lines
542 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 定义要搜索的目录
search_dir="."
# 定义要从文件名中移除的模式
pattern="~20240329-150359"
# 使用find命令查找所有包含模式的文件并使用mv命令重命名
find "$search_dir" -type f -name "*$pattern*" | while read file; do
# 使用basename和dirname获取文件的基本名和目录名
dir=$(dirname "$file")
base=$(basename "$file")
# 使用mv命令重命名文件移除模式部分
mv "$file" "$dir/${base/$pattern/}"
done
echo "所有文件已成功重命名。"