|
发表于 2003-12-15 17:18:08
|
显示全部楼层
File Archivers and Compression
==============================
文件档案和压缩
In this section, I want you to learn some extra things that will make life interesting. You will need to learn about archives. Archives come in many different formats. Archive is a general term for a software package. You may have heard of a "tarball": this is a form of archive. The file extensions tell us what type of archive the file is. Generally they come in forms of .tgz, .tar.gz, .tar.bz2, .gz, etc.
在这一节里,我想你学一些使得生活有趣一点的额外的事情.你会需要学习档案打包.档案来自于许多不同的格式.归档是软件包的一个惯用术语.你或许听过”tarball”:这是一种归档档案.文件扩展名告诉我们归档包裹文件是哪一种格式的.一般他们以 .tgz, .tar.gz, .tar.bz2, .gz等等形式存在.
"Archiving" is a method of packaging files. It has been around since the early days of computing. The `tar' command that we use when working with archives stands for "tape archiver". It was originally used to create archived files for backup on large tape drives.
“归档”是包装文件的的一种方法.它从计算机的早期历史开始就存在.我们对归档包裹文件使用的'tar'命令代表”磁带归档”它一开始是使用来在大的磁带驱动器上创建文件的.
Closely associated with archiving is the concept of "compressing". Various algorithms can be used to pack data into a smaller format. Archives are often compressed before being distributed; for example, a tarball may have the extension `.tar.gz', which means that the tarball is a `tar' archive that has been compressed using `gzip'. Most software that you try and install from source-code will be packaged this way. I will try to give you some examples; if you're confused, always consult the info pages.
紧紧和归档相关联的是概念”压缩”.各种各样的算法可以用来压缩数据成更小的格式.归档文件经常在分发之前先压缩;例如,一个tarball也许有扩展名'.tar.gz',意思是这个tarball是一个已经用'gzip'压缩过的'tar'包.大多数从源码安装的软件会以这个方式打包.我会给你一些例子;如果你觉得迷惑,常常查阅info页.
Let's say we get a `tar' file that has some documents you want to read. Make sure that you are in your home directory, then type:
让我们假设我们得到了一个包含一些你想阅读的文档的'tar'包.确信你在你的home目录下,然后输入:
bash-2.05$ tar xv docs.tar <ENTER>
After running this command, you would see the contents of the tar file extracted to your home directory. The `x' stands for "extract" and the `v' means "verbose", which shows us the contents of the archive as it's being decompressed. Compressing a file or directory is very similar. You would use type:
执行这个命令后,你会看到tar文件的内容被解压到你的home目录.'x'代表”extract解压”而'v'意思是”verbose详述”,显示归档文件的内容好像它被解压了一样.压缩一个文件或者目录是很类似的.你会输入:
bash-2.05$ tar -cv new.tar foo1/ foo2/ <ENTER>
The `-c' is to create the tar file. We add the name of the tar file, then the contents that we want. In the above example, we created a file called `new.tar' and we added the directories `foo1/' and `foo2/' to the tar file. With the `-v' option we see what is being added.
'-c'是创建tar文件.我们加了tar文件的名字,然后是我们想加进去的内容.在上面的例子中,我们创建了一个叫做'new.tar'的文件并且增加了'foo1'和'foo2'文件到这个tar文件里.通过'-v'选项我们看到了什么文件正在加进去.
The `gzip' compression format is commonly used in the GNU system. Files with the extionsion `.gz' are associated with `gzip'. The utilities `tar' and `gzip' work so well together that people have patched the tar command so that it can compress and decompress `gzip'ed files. Note, however, that `tar' cannot be used to decompress `gzip'ed files that are not `tar' archives.
'gzip'压缩格式在GNU系统中常用.带扩展名'.gz'的文件和'gzip'关联.'tar'和'gzip'实用程序在一起工作的如此之好所以人们给tar命令打了补丁这样它可以压缩和解压'gzip'过的文件.注意,然而,'tar'无法用来解压'gzip'压缩过的不是'tar'归档的文件.
bash-2.05$ tar -zxv file.tar.gz <ENTER> #This file was compressed once with tar then with gzip
bash-2.05$ gzip -d file.gz <ENTER> #notice no tar in filename means you
use
gzip
In the first example, the `z' after the `tar' command is the option that tells `tar' that the file has been `gzip'ed. The second example is the `gzip' command, using the `d' option to decompress `file.gz'. `gunzip' is a command that is equivalent to `gzip -d', but more intuitive.
在第一个例子里,跟在'tar'命令后的'z'是一个告诉'tar'文件是被'gzip'过的.第二个例子是'gzip'命令,使用'd'选项解压'file.gz'.'gunzip'是一个等效于'gzip -d'的命令,但是更直观点.
bash-2.05$ gunzip file.gz <ENTER>
To compress a `tar' files, or any file, using `gzip', you would type:
要使用'gzip'压缩一个'tar'文件,或者任何文件,你会输入:
bash-2.05$ gzip -9 file.tar <ENTER>
The `-9' means best compression. There are many options available for `gzip'. A quick browse through the info pages will tell you everything you need to know.
'-9'意味着最高的压缩率.'gzip'还有许多可用选项.一个穿越info页的快速浏览会告诉你你需要知道的任何事.
Another common form of compression is the `bzip2' format. `tar' archives compressed using `bzip2' usually have the extension `.tar.bz2'. This format is known to be one of the best compression utilities. To extract a bzip2 file you would type:
另外一种通用的压缩形式是'bzip2'格式.使用'bzip2'来压缩的'tar'包经常用扩展名'.tar.bz2'.这种更是是已知的可用程序里最好的一种之一.要解压缩一个bzip2文件你会输入:
bash-2.05$ bunzip2 file.bz2 <ENTER>
Like the `gzip' format, the `bzip2' format has many options. You will probably see `bzip2' compressing `tar' files. The `bzip2' utility many other commands linked to it. To extract a file that has been archived with `tar' and compressed with `bzip2', you would do something similar to the following:
像'gzip'格式一样,'bzip2'格式有许多选项.你大概看见过bzip2压缩的'tar'文件.'bzip2'和许多别的命令联系在一起有许多可用用途.要解压一个用'tar'打包和'bzip2'压缩了的文件,你只需要做一些类似于下面的操作:
bash-2.05$ bzcat file.tar.bz2 |tar -xv <ENTER>
The `bzcat' command is a combination of `bunzip2' and `cat'. We `bzcat' the file, then pipe(|) the file to the `tar' command. Once again, I use `-x' to extract the file, and `-v' to see its contents. To compress a file using `bzip2' you would type:
'bzcat'命令是'bunzip2'和'cat'命令的组合.我们'bzcat'文件,然后用管道(|)传给'tar'命令.我再一次使用'-x'解压文件,'-v'查看内容.要用'bzip2'压缩文件你会输入:
bash-2.05$ bzip2 -z file1.txt <ENTER>
This command compresses `file1.txt' to `file1.txt.bz2'. You can also use the `'-9'' option for best compression.
这个命令压缩'file1.txt'到'file2.txt,bz2'.你也可以使用'-9'选项得到最好的压缩率.
Hopefully, this little chapter has gotten you more interested in using GNU/Hurd. If you are still confused, please read the info pages for the command that's giving you trouble. The command `info' will give you a list of all the programs on your Hurd machine that have documentation with them. The best way to learn GNU utilities is to read and practice. GNU/Hurd is just like music or sports: you can never learn enough. This chapter is meant to give you a stepping stone to freedom.
但愿,这一章已经使得你对使用GNU/Hurd更感兴趣.如果你依然迷惑,请阅读info页查找给你带来麻烦的命令.命令'info'会给你一个在你的Hurd机器上携带着文档的所有程序的列表.学习GNU实用程序的最好方式是阅读和实践.GNU/HUrd就象音乐或者运动:你永远学不够.这一章的意味是给你自由的进一步的铺路石. |
|