How to use the tar command to tar up a directory

I have a directory called webapps, all the contents  i need to compress into a tar file.  How can I do this? Should I use tar or gzip which is the better solution?
singh101Asked:
Who is Participating?
 
GundaresConnect With a Mentor Commented:
OK, try to use it like this:

$ tar -cf - *|gzip > ../webapps.tar.gz

you should do it inside of 'webapp' folder. If you have not write rights to the upper folder (..), put archived file into your home directory: /home/USERNAME/webapps.tar.gz. If you have a 'dot' files (like .htaccess) you should list them after an asterisk:

$ tar -cf - * .htaccess |gzip > ../webapps.tar.gz
Do not use a '.*' pattern, try '.ht*' or something similar.
0
 
Andre ThibodeauConnect With a Mentor ITCommented:
tar contents of folder foo in foo.tar
tar -cvvf foo.tar foo/
0
 
GundaresCommented:
You can also gzip (or bzip2) your archive using only one 'tar' command like this:

$ tar -zcf webapps.tar.gz webapps
$ tar -jcf webapps.tar.bz2 webapps

These commands assume that your current folder is one level upper that your 'webapps' folder
0
 
singh101Author Commented:
tar -zcf webapps.tar.gz webapps
when I run this command it is returning tar: z unknown function modifier. ideally I want to tar up the contents of webapps and not the webapps folder. If I cd to webapps and then replace . with webapps. Is that ok?
0
All Courses

From novice to tech pro — start learning today.