Dropbox服务生成(错误)大量冲突文件。这些文件在我的本地linux文件系统上。
示例文件名=编译(主人的冲突副本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
答案 0 :(得分:2)
当前目录中的所有文件:
for file in *
do
newname=$(echo "$file" | sed 's/ (.*)//')
if [ "$file" != "$newname" ]; then
echo moving "$file" to "$newname"
# mv "$file" "$newname" #<--- remove the comment once you are sure your script does the right thing
fi
done
或递归,将以下内容放入我打电话给/tmp/myrename
的脚本中:
file="$1"
newname=$(echo "$file" | sed 's/ (.*)//')
if [ "$file" != "$newname" ]; then
echo moving "$file" to "$newname"
# mv "$file" "$newname" #<--- remove the comment once you are sure your script does the right thing
fi
然后find . -type f -print0 | xargs -0 -n 1 /tmp/myrename
(这在命令行上很难做到,而不使用额外的脚本,因为文件名包含空格)。
答案 1 :(得分:1)
一个小小的贡献:
我这个剧本有问题。名称中包含空格的文件不会复制。所以我修改了第17行:
-------切-------------切---------
if test -f "$newname"
-------切-------------切---------
答案 2 :(得分:1)
上面显示的这个脚本现在已经过时了;以下内容适用于编写本文时在Linux Mint上运行的最新版Dropbox:
#!/bin/bash
#modify this as needed
folder="./"
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/ (.*Case Conflict.*)//')
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
答案 3 :(得分:1)
您可以使用工具Dropbox Conflict Fix。它解决了我所有冲突的复制文件。