0

I'm trying to find and zip all my pdf files. find works fine:

find -iname "*.pdf"

I want to zip everything that is printed into 1 file. Thank you for your time.

0

2 Answers 2

1

Something like this might work:

find . -iname '*.pdf' -print0 | xargs -0 zip archive.zip

That will store everything using its original filesystem path (so e.g. foo/bar/myfile.pdf will be stored in the zip file as foo/bar/myfile.pdf).

2
  • Wow! It worked like magic! You are the BOSS! God bless you, my friend.
    – JEFERSON D
    Jun 21, 2023 at 23:33
  • You don't even need xargs: find . -iname '*.pdf' -exec zip archive.zip {} + Jun 28, 2023 at 16:46
0

You don't need find for that.

#!/bin/bash
shopt extglob
shopt nocaseglob
zip zipfile.zip **/*.pdf

(Untested, since typed on my phone)

3
  • It only works on one level unfortunately ( home/folder/.pdf ) How can it go down to all subdirectories that have pdf files? Thank you.
    – JEFERSON D
    Jun 21, 2023 at 23:25
  • 1
    That **/*.pdf expression is meant to match multiple levels, but (a) the answer does not enable the correct option (globstar), and (b) the answer isn't using the correct syntax for shopt (you need shopt -s <optionname> to enable an option, so shopt -s globstar and shopt -s nocaseglob). With those changes this should work.
    – larsks
    Jun 21, 2023 at 23:44
  • Ah @larsks thanks for checking my answer. I'll need to fix it :) Jun 22, 2023 at 6:13

You must log in to answer this question.

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