Search code examples
linuxshellpdfjpeg

How to convert jpg files in subfolders to one each pdf file in one step in linux?


I have folder A with the subfolders B, C and D. My jpg files are in the subfolders. I know the command:

convert *.jpg output.pdf

converts all jpg in the folder to one pdf. But I can't use this command, when I am in the folder A. Do you know what command I can use when I'm in folder A to convert the jpg files in the subfolder as following:

B: *.jpg -> B.pdf  
C: *.jpg -> C.pdf  
D: *.jpg -> D.pdf

I think you get what I mean. I don't want all jpg files of the subfolders in one pdf, but I want one pdf for each subfolder. I hope you can help me out here.


Solution

  • convert ./B/*.jpg outputB.pdf
    

    Or if you want to do all in one loop (assuming that you are in dir A):

    for dir in $(find . -maxdepth 1 -type d)
    do
        convert ./$dir/*.jpg output.$dir.pdf
    done