简体   繁体   English

如何在 bash 脚本中将一个文件夹中的所有 tif 文件转换为 pdf 并保存在另一个位置而不循环?

[英]How to convert all tif files in one folder to pdf and save in another location without looping through, in bash script?

find /home/folder1/folder2/folder3/my\ Raw\ Data/"$1"/"$2"/"$3"/"$4" -type f -name "*.tif" -exec bash -c 'tiff2pdf "$1" -o "${1%.tif}".pdf' - '{}' \;

This is my bash script to convert tif files in /home/folder1/folder2/folder3/my\ Raw\ Data/"$1"/"$2"/"$3"/"$4" to pdf.The output pdf will also get saved in same location, But I want the output pdf in /home/folder1/folder2/folder3/my\ Raw\ Data/"$1"/"$2"/"$3"/backup . This is my bash script to convert tif files in /home/folder1/folder2/folder3/my\ Raw\ Data/"$1"/"$2"/"$3"/"$4" to pdf.The output pdf will also get saved在同一位置,但我想要/home/folder1/folder2/folder3/my\ Raw\ Data/"$1"/"$2"/"$3"/backup中的 output pdf 。 How is it possible without using a loop?不使用循环怎么可能? Is there any solution for this?有什么解决办法吗?

Here's a way to get them all done in parallel, without any loops, using GNU Parallel :这是一种使用GNU Parallel让它们并行完成的方法,没有任何循环:

cd /path/to/tiffs && parallel tiff2pdf {} -o ../backup/{.}.pdf ::: *tif

Try like this first to see what it would do, without doing anything:首先尝试这样,看看它会做什么,而不做任何事情:

cd /path/to/tiffs && parallel --dry-run tiff2pdf {} -o ../backup/{.}.pdf ::: *tif

Here's another way with ImageMagick :这是ImageMagick的另一种方式:

cd /path/to/tiffs && magick mogrify -path ../backup -format PDF *tif

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

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