Thursday, August 2, 2007
Untarring and unzipping files
Using 'tar' and 'gzip' sort of supposes that you're going to want to "untar" and "unzip" these files at one point or another.
The easiest way for doing this is to use 'tar' for the whole process. You would locate the zipped tarball in question and then ask yourself a question:
Did I make any changes to the files inside the tarball after I made it? If you did, then you've got an old tarball. If you untarred it in the same directory, you'd overwrite the existing ones. If you would like a copy of the old file, untar it in a different directory. If you don't want the old files, then you should make a new tarball. It's pretty standard backup practice.
When you've decided what you want to do, to proceed with the "untarring", issue this command:
tar -zxvpf my_tar_file.tar.gz
I've used my preferred options. I'll explain them:
* -z - unzip the file first
* -x - extract the files from the tarball
* -v - "verbose" (i.e tar tells you what files it's extracting)
* -p - preserves dates, permissions of the original files
* -f - use the file in question (if you don't specify this, tar just sort of sits around doing nothing)
The files are extracted and your original tarball is preserved (my_tar_file.tar.gz).
You can also untar the file and then use gzip separately. Just leave the z option out of the previous example and type:
gzip -d my_tar_file.tar.gz or
gunzip my_tar_file.tar.gz
(gunzip runs gzip -d "automagically"!)
These commands are good if you've just zipped a regular file (not a tarball).
Other compression tools
zip
Most Linux distributions come with other tools to compress files. One of these is zip, famous in the MS-DOS/Windows world. If you're planning on compressing files to give to someone who (still) uses the Windows operating system, this might be your best bet. You can also use unzip if someone gives you a file compressed with 'zip'. Consult the man file ( man zip) for specific instructions on using this tool.
bzip2
There is also another tool that is rapidly gaining acceptance in the Linux world: bzip2. As a matter of fact, the Linux kernel source package, usually comes "bzipped". When you compile a kernel (create a custom kernel for yourself from source) there is an option to create a bzipped kernel. This is supposed to become the official way of doing it in the near future, so it may be a good idea to get to know 'bzip2'
For all practical purposes you would use this tool in the same way as you would 'gzip'. The compression factor is supposed to be a little better. There are some differences in options for more advanced users. Consult man bzip2 for more information.
The easiest way for doing this is to use 'tar' for the whole process. You would locate the zipped tarball in question and then ask yourself a question:
Did I make any changes to the files inside the tarball after I made it? If you did, then you've got an old tarball. If you untarred it in the same directory, you'd overwrite the existing ones. If you would like a copy of the old file, untar it in a different directory. If you don't want the old files, then you should make a new tarball. It's pretty standard backup practice.
When you've decided what you want to do, to proceed with the "untarring", issue this command:
tar -zxvpf my_tar_file.tar.gz
I've used my preferred options. I'll explain them:
* -z - unzip the file first
* -x - extract the files from the tarball
* -v - "verbose" (i.e tar tells you what files it's extracting)
* -p - preserves dates, permissions of the original files
* -f - use the file in question (if you don't specify this, tar just sort of sits around doing nothing)
The files are extracted and your original tarball is preserved (my_tar_file.tar.gz).
You can also untar the file and then use gzip separately. Just leave the z option out of the previous example and type:
gzip -d my_tar_file.tar.gz or
gunzip my_tar_file.tar.gz
(gunzip runs gzip -d "automagically"!)
These commands are good if you've just zipped a regular file (not a tarball).
Other compression tools
zip
Most Linux distributions come with other tools to compress files. One of these is zip, famous in the MS-DOS/Windows world. If you're planning on compressing files to give to someone who (still) uses the Windows operating system, this might be your best bet. You can also use unzip if someone gives you a file compressed with 'zip'. Consult the man file ( man zip) for specific instructions on using this tool.
bzip2
There is also another tool that is rapidly gaining acceptance in the Linux world: bzip2. As a matter of fact, the Linux kernel source package, usually comes "bzipped". When you compile a kernel (create a custom kernel for yourself from source) there is an option to create a bzipped kernel. This is supposed to become the official way of doing it in the near future, so it may be a good idea to get to know 'bzip2'
For all practical purposes you would use this tool in the same way as you would 'gzip'. The compression factor is supposed to be a little better. There are some differences in options for more advanced users. Consult man bzip2 for more information.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment