Compressing and Archiving files

tar 

tar is just confusing to some people so here is my attempt to make it easy. 

Say you download a file called test.tar to untar it you simply type tar -xvf test.tar and its contents will be extracted. Most of the time you will download test.tar.gz files which are gziped kind of like winzip or pkzip. To deal with them type tar-xvzf test.tar.gz to extract the files. 

tar can also be used to archive files. 

type tar -cvf test.tar * this will archive all files in your current directory into a file called test.tar. 
This is a useful way to backup files. 

To also compress or zip them type tar -cvzf test.tar.gz * . 
gzip gunzip bzip etc 
These are compression commands type man gzip or bzip to see how to use them. Basically take a file called test. Type gzip test it compresses the file and adds the .gz extenstion. Bzip acts just the same. Remember that if you have a file that is gzipped and tarred type tar -xvzf to extract it or tar -cvzf to create it. 

- tar - file compression and archiving utility. I find the syntax of this command to be frustratingly opaque. The following works for me. To use this command to unzip gzipped tarballs in verbose mode, use 

- tar -xvzf filename.tgz 
To create a tarball from files in a given directory and its subdirectories, use 

- tar -cvzf filename.tgz sourcename 
Sourcename can be the name of a single file, a wildcard such as *, or the name of a subdirectory. There seem to be two different conventions concerning gzipped tarballs. One often encounters .tar.gz. The other popular choice is .tgz. Slackware packages use the latter convention. The command can also be used to archive a file, a group of files, or a directory (with its subdirectories) on tape or onto floppies. If the material to be archived exceeds the capacity of the backup medium, the program will prompt the user to insert a new tape or diskette. Use the following command to back up to floppies: 

- tar -cvf /dev/fd0 filename(s) or directoryname(s) 
The backup can be restored with 

- tar -xvf /dev/fd0 
Tar can be used for other things. To mirror all the files and subdirectories in from-stuff to to-stuff, use the commands 

- cd from-stuff 

- tar cf - . | (cd ../to-stuff; tar xvf -) 
No tar file is ever written to disk. The data is sent by pipe from one tar process to another. This example is taken from Running Linux, p.177. To list the table of contents of a tar archive, use 

- tar tvf tarfile 
To extract individual files from a tar archive, use 
tar xvf tarfile files

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.