我有许多没有名字扩展分散在子目录中的pdf文件。这使我的书目软件无法组织它们。我希望识别这些文件,在一个新目录中收集它们,并在那里添加缺少的.pdf扩展名。
发布于 2022-02-10 12:05:31
正如注释中所述,您可以使用核心linux工具- find
和file
命令。下列工作人员应能发挥作用:
find your_starting_path -print0 |xargs -0 file |grep 'PDF document' > potential_pdfs.txt
然后,您可以验证您的potential_pdfs.txt文件,如果所有找到的文件看起来合理,并最终清理该文件。最后,您可以使用该文件作为清理脚本的输入:
targetdirectory=some_path_for_pdfs
cat potential_pdfs.txt |awk -F: '{print $1}' | while read filename; do
base=$(basename "$filename")
cp -v "$filename" "$targetdirectory/$base.pdf"
done
最终,您可能希望使用mv删除原始文件。小心移除它们。这个脚本不适用于名字中包含:
的文件,因为您需要稍微调整一下它。
https://stackoverflow.com/questions/70917039
复制相似问题