我有大量的由保管箱服务生成(不正确)的冲突文件。这些文件在我的本地linux文件系统上。批量重命名Dropbox冲突文件
示例文件名=编译(硕士矛盾复制2013年12月21日).SH
我想重新命名其正确的原始名称的文件,在这种情况下compile.sh并删除任何现有文件,那个名字。理想情况下,这可以是脚本或以这种方式递归。
编辑
望过去提供的解决方案和玩弄,并进一步研究后,我拼凑起来的东西,对我来说效果很好:
#!/bin/bash
folder=/path/to/dropbox
clear
echo "This script will climb through the $folder tree and repair conflict files"
echo "Press a key to continue..."
read -n 1
echo "------------------------------"
find $folder -type f -print0 | while read -d $'\0' file; do
newname=$(echo "$file" | sed 's/ (.*conflicted copy.*)//')
if [ "$file" != "$newname" ]; then
echo "Found conflict file - $file"
if test -f $newname
then
backupname=$newname.backup
echo " "
echo "File with original name already exists, backup as $backupname"
mv "$newname" "$backupname"
fi
echo "moving $file to $newname"
mv "$file" "$newname"
echo
fi
done
感谢您的解决方案Guntram。它使我走上正轨。我已采取您提供的内容并对其进行了修改/扩展,以更好地适应我的目的。了解更多关于linux bash(尊重)的力量。 – cemlo