简体   繁体   English

Linux 查找重复项将附加文件发送到新目录

[英]Linux finding duplicates send appended files to new directory

I've been struggling with this,part of a job interview I found online but cant figure it out.我一直在为此苦苦挣扎,这是我在网上找到的求职面试的一部分,但无法弄清楚。

**Obtain a list of paths to all PDF and pdf files within the source directory. **获取源目录中所有 PDF 和 pdf 文件的路径列表。

For every file in this list Check to see if there is a corresponding doc file in the same directory.对于此列表中的每个文件,检查同一目录中是否有相应的 doc 文件。

If there is do nothing如果什么都不做

If there is not如果没有

Check to see if there is already a PDF file in the target directory with this name.检查目标目录中是否已存在具有此名称的 PDF 文件。

If there is not, copy the PDF file to the target directory as is.如果没有,请将 PDF 文件原样复制到目标目录。

If there is and it is not identical, copy the PDF file to the target directory but append “_” to the filename.**如果存在且不相同,请将 PDF 文件复制到目标目录,但在文件名后附加“_”。**

Got the pdf with find but cant loop the files.得到了带有 find 的 pdf 但无法循环文件。

find ../mnt -iname "*.pdf" 

there are lots of ways to do this but starting with your find command有很多方法可以做到这一点,但从您的 find 命令开始

for i in $(find ../mnt -iname "*.pdf"); do z=$(basename -s .pdf $i); echo $z;done

this will print out a list of filenames with the suffixes removed.这将打印出删除后缀的文件名列表。 Then it is simple to do something like然后做类似的事情很简单

if [ -e "..mnt/$z.doc" ]; then

To check if the doc file is there检查doc文件是否存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM