免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1462 | 回复: 0
打印 上一主题 下一主题

Archiving Files for Newbies [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-22 10:52 |只看该作者 |倒序浏览
There are plenty of ways you can archive files in Unix, mostly with the help of third-party applications
There are plenty of ways you can archive files in Unix, mostly with the help of third-party applications.
The first one is "tar". The name comes from "tape archiver", as it was once used for writing files to tapes. It still offers that functionality, but is also quite useful when archiving files on disk.
!! Note -- tar does NOT use compression. It simply creates a single archive file from a number of files and/or directories.
** Basic archiving example -- the following command will create an archive named somefile.tar, which will contain a number of files (listed at the end of the command):
tar cvf somefile.tar file1 file2 file3
- "c" is for "create".
- "v" is for "verbose" -- shows the name of files as they are archived.
- "f" is for "file" -- this is a standard option.
** Basic de-archiving example:
tar xvf somefile.tar
- "x" is for "extract"
** List the files in an archive without extracting them:
tar tvf somefile.tar
- "t" is for "test" (if I am not mistaken).
!! Note -- the commands you just saw work recursively. You can apply the same commands to whole directory structures.
Another command is "gzip". It is simply a zip utility by the GNU project (
[color="#eee3ff"]http://www.gnu.org
). It comes standard on most Unix systems and performs file compression.
Usually, when you have to archive a large number of files/directories, you use tar first, and then gzip.
** Compressing a file. The following will produce a compressed file named somefile.tar.gz.
gzip somefile.tar
** Uncompressing a file. This will produce the original file, somefile.tar.
gzip -d somefile.tar.gz
** Uncompressing a file and pointing the output to the screen instead of a file. This is useful in a situation described below.
gzip -dc somefile.tar.gz
Finally, here are several useful examples of how to use tar and gzip together.
** Uncompress and untar an archive. This will leave the original *.tar.gz file in place, as well as will produce the end result:
gzip -dc somefile.tar.gz | tar xvf -
What we just did was unzip the file, point the output to the console, then pipe that output to the tar command. The "-" at the end is mandatory.
** Some Unix systems (such as Linux) offer a shorter version of the above command, but keep in mind that it is not supported everywhere:
tar xvfz somefile.tar.gz
Similarly, you can create an archive on Linux using the same logic:
tar cvfz somefile.tgz file1 file2 file3
"tgz" is another alternative for "tar.gz".


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10290/showart_48825.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP