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

I am trying to zip up a directory and have the contents emailed to me. How could I do this?

I have a cron setup for mysql backup which ends like:

 | gzip | uuencode public_html_backup.gz | mail

Would I be able to perform a similar thing for zipping a directory?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

To back up /path/to/parent/directory, you can use

cd /path/to/parent && tar -cjf - directory | uuencode | mail -s "directory backup on $(date)"

This uses bzip2 compression. If you prefer gzip compression (uses less CPU but compresses less), replace -czf by -cjf. If you prefer zip format, replace tar -czf - directory by zip -r - directory.

share|improve this answer

I dont know your entire command but yes it would work, for example:

uuencode | mail -s "My Mail Subject"

another example:

tar cvf - Folder | gzip > my_backup.tar.gz | uuencode my_backup.tar.gz | mail -s "Subject"

another example:

gzip -c somefile.tar | uuencode somefile.tar.gz  | mail -s "My Backup"

You could use mutt aswell:

mutt -a file.tar.gz -s "subject of message"

For a more complete guide click here!

share|improve this answer
Thank you also for this - I wish I could accept two answers – Malachi Sep 25 '10 at 12:23
@Malachi Soord np aslong as you got it working, its all good :) – Prix Sep 25 '10 at 12:30
It actually took a combo of both your solutions to get what I required – Malachi Sep 25 '10 at 13:28

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.