返回顶部

收藏

tar

更多
To create an archive using tar, use a command like this, which bundles all the files in the current directory that end with .doc into the alldocs.tar file:
tar cvf alldocs.tar *.doc

Here's a second example, which creates a tar file named panda.tar containing all the files from the panda directory (and any of its subdirectories):

tar cvf panda.tar panda/

In these examples, the c, v, and f flags mean create a new archive, be verbose (list files being archived), and write the archive to a file. You can also create tar files on tape drives or floppy disks, like this:

tar cvfM /dev/fd0 panda Archive the files in the panda directory to floppy disk(s).
tar cvf /dev/rmt0 panda Archive the files in the panda directory to the tape drive.

The /dev/fd0 entry is Linux-ese for "floppy drive zero" (your A drive under DOS), and /dev/rmt0 means "removable media tape zero," or your primary tape drive. The M flag means use multiple floppy disks--when one disk is full, tar prompts you to insert another.

To automatically compress the tar file as it is being created, add the z flag, like this:

tar cvzf alldocs.tar.gz *.doc

In this example, I added the .gz suffix to the archive file name, because the z flag tells tar to use the same compression as the gzip command.

To list the contents of a tar file, use the t (type) flag in a command, like this:

tar tvf alldocs.tar List all files in alldocs.tar.

To extract the contents of a tar file, use the x (extract) flag in a command, like this:

tar xvf panda.tar Extract files from panda.tar.

This will copy all the files from the panda.tar file into the current directory. When a tar file is created, it can bundle up all the files in a directory, as well as any subdirectories and the files in them. So when you're extracting a tar file, keep in mind that you might end up with some new subdirectories in the current directory.

We've used several different flags in the sample tar commands so far. Here's a list of the most common flags:

c Create a new archive.
t List the contents of an archive.
x Extract the contents of an archive.
f The archive file name is given on the command line (required whenever the tar output is going to a file)
M The archive can span multiple floppies.
v Print verbose output (list file names as they are processed).
u Add files to the archive if they are newer than the copy in the tar file.
z Compress or decompress files automatically.

Read more: http://lowfatlinux.com/linux-tar.html#ixzz1b8kwCjFL

标签:bash

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. techug 发表 2018-10-12 02:46:17 10 个 Linux 中方便的 Bash 别名
  2. vpsee 发表 2014-10-15 09:54:44 使用 Flask 搭建静态博客
  3. phpor 发表 2018-09-19 09:08:11 bash 之 信号处理
  4. techug 发表 2018-08-15 00:44:09 单行bash编程技巧(一)
  5. phpor 发表 2018-07-27 09:21:39 bash 之变量声明周期
  6. techug 发表 2018-07-23 05:21:45 译 | Bash编程中43种易犯的错误
  7. AngryFox 发表 2018-07-22 03:07:52 shell /bin/bash^M: bad interpreter报错的解决方法
  8. admin 发表 2018-07-18 07:20:30 大神教你DIY高性能运维堡垒体系
  9. phpor 发表 2018-07-17 06:50:47 tcp server in bash
  10. phpor 发表 2018-07-17 06:59:03 bash 之变量与函数
  11. techug 发表 2018-07-16 01:56:38 Linux bash 数组用法技巧
  12. phpor 发表 2018-07-16 02:30:59 cfree ( free in container)

发表评论