search

Home  >  Q&A  >  body text

linux 下如何删除指定目录的重复文件

linux命令行,如何删除某个指定目录A内与另一个或多个目录B重复的文件?
目录B内的文件保留
fdupes貌似不能指定只删除A的

高洛峰高洛峰2783 days ago727

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:15:59

    Checked dozens of web pages and found this nearly satisfactory solution
    http://unix.stackexchange.com/questions/146197/fdupes-delete-files-aft...

    However, the exclamation point in the regular expression does not seem to have the effect of clearing blank lines, so it is changed to d;
    fdupes --recurse A/ B/ | sed '/^A/d; /^$/d; s/.*/"&"/' | xargs rm

    But there is still a small problem. If there is a duplicate file in A, but the file is not in B, fdupes will also list it as a result, resulting in accidental deletion. Please think again

    reply
    0
  • Cancelreply