1

I have three levels of folders like main, sub-1 and sub-2. my main folder has lot of sub-1 folders and sub-1 has lot of sub-2 folder with JPG images inside.

I copy JPG files from sub-2 to its parent sub-1 folder FROM main folder by using this command.

find . -type f -name "*.jpg" -exec sh -c 'for p; do
  cp "$p" "${p%/*/*}"
done' _ {} +

Now I have to convert all jpgs into one pdf file inside each sub-1 folder from my MAIN folder, so there will be my all copied jpgs along with converted pdf in sub-1 (pdf name should be the folder name ex: sub-1). after convert finished I have to delete the copied jpgs only inside sub-1 folder (not original jpgs), so there will be many sub-2 folders with a single pdf file.

I am using img2pdf library to covert my images. and I tried this command below it does not do the work, I could not find any solution. Now how do I make this works?

find . -name '*.jpg' -type f -exec bash -c 'img2pdf *.jpg -o "${PWD##*/}".pdf' {} + \

1 Answer 1

0

This worked for me:

find . -name '*.png' -type f -exec bash -c 'name={} &&  img2pdf {} -o "${name/.png/.pdf}" ' \;
1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 15, 2023 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .