Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I start on shell and i don't know how to compress a folder including just the .jpg and .jpeg files.

Anyone can help me?

Thank you

share|improve this question
Can you please clarify the question? Do you mean to just "include" .jpg files in the archive without compression operations performed on those files, while compressing all other files? – cjc Nov 3 '11 at 12:03
$ tar cvf jpeg.tar $(find /path/to/folder -iregex ".*\.jpe?g")
$ find /path/to/folder -type f -iregex ".*\.jpe?g" | xargs tar cvf jpg.tar
share|improve this answer
I would prefer the latter version as the first one might fail in case of many files to compress. This is avoided by the second variant which uses xargs to overcome that problem. (@quanta: a little bit of explanation would be helpful in a case like that). – Sven Nov 3 '11 at 11:31

Go to folder

zip archive *.jpg *.jpeg

else, from anywhere

zip archive /path/to/folder/*.jpg /path/to/folder/*.jpeg

archive is the output file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.