Create a tar file of an entire directory and its sub-directories
Linux November 2nd, 2005To create a tar archive of an entire directory including all files and sub-directories:
tar -cvf mytarfile.tar mydir/
To create a tar archive of an entire directory including all files and sub-directories:
tar -cvf mytarfile.tar mydir/
July 15th, 2007 at 12:32 pm
tar -cvfz mytarfile.tgz mydir/ will also compress the directory (gzip)
August 8th, 2007 at 2:07 pm
Also … for a more universally compatible file try
# zip -rv9 myzipfile.zip /mydir
-9 is for maximum compression
-v is for verbose output
-r is recursive directories
May 19th, 2008 at 10:45 am
The problem with the zip format is that it does not store file permissions.
December 22nd, 2008 at 1:22 pm
I thank you so muhc for putting this code up. I can never remember it and always load this page when I need to make a backup.
Do you have any good ways to just get one file out of the tar file?
March 17th, 2009 at 8:46 am
using
tar -cvfz mytarfile.tgz mydir/
returns
tar: mytarfile.tgz: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
so use it without dash in the beginning of the command as in:
tar cvfz mytarfile.tgz mydir/
and it works beautifully.