检查重复文件

时间:2018-02-26 12:39:39

标签: shell

这是我的备份脚本,我有一个问题。 我想要。有重复文件时不要播放MV。 然后我希望脚本转到下一个。

#!/bin/sh

LocalLogMoveDATA=$(exec date -d -1days '+%Y%m%d')

DATAlist="AA BB CC DD EE FF"

for DATAdir in $DATAlist
do

if [ -e "/Tick/$DATAdir/$LocalLogMoveDATA" ]

then

        rm -rf /apple/super/mail/rec/data/$DATAdir/$LocalLogMoveDATA

  else

        mv /apple/super/mail/rec/data/$DATAdir/$LocalLogMoveDATA /Tick/$DATAdir/

fi

done

1 个答案:

答案 0 :(得分:0)

如果您的意思是“请勿mv如果目的地中已存在同名文件”,则-n选项会执行此操作。

您的脚本还存在其他一些风格问题。请参阅内联评论。

#!/bin/sh
# exec did nothing useful here
LocalLogMoveDATA=$(date -d -1days '+%Y%m%d')
# keeping the directory names in a variable didn't seem to serve any purpose
for DATAdir in AA BB CC DD EE FF
do
    # add a variable to keep this in one place
    datadir=/apple/super/mail/rec/data/$DATAdir/$LocalLogMoveDATA
    # fix indentation of the loop body
    if [ -e "/Tick/$DATAdir/$LocalLogMoveDATA" ]        
    then
        # add missing quotes
        rm -rf "$datadir"
    else
        # ditto, and add -n option
        mv -n "$datadir" "/Tick/$DATAdir/"
    fi
done