LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: storm the front

关于tar的参数

[复制链接]
发表于 2004-9-10 00:12:02 | 显示全部楼层
唔,sorry,刚才那个说得不对,我把帖图给出来,大家看看,就是包括a,aa,yandom三个文件夹和b,bb两个文件。但是我希望排除a的时候却导致这样的结果:
发表于 2004-9-10 00:13:06 | 显示全部楼层
这样:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2004-9-10 00:26:20 | 显示全部楼层
用find试试看
$(find -path "./a" -prune -o -type f -print)
ps:
ls !(backup|backup.gz)这种用法是ksh的
发表于 2004-9-10 06:48:32 | 显示全部楼层
tar -czvf Test.gz $(ls|grep -d read -v "a")
发表于 2004-9-10 16:08:20 | 显示全部楼层
两位的方法我都试过了,结果如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2004-9-10 16:11:39 | 显示全部楼层
实际上,我觉得这样一个命令不应该太复杂。设计者应该对此有比较简单的选项。本来我以为--exclude和--exclude-from是理想的选择,可惜不行,用上面建立一个list文件的办法我也觉得比较麻烦。
我猜一定有更简单的方法处理这种常见问题
发表于 2004-9-10 16:34:23 | 显示全部楼层
现在大体明白了:
不包含单个文件/文件夹,可以使用--exclude
不包含多个文件/文件夹,只能使用--exclude-from
发表于 2004-9-11 01:02:02 | 显示全部楼层
[php]

jia@hua:/etc$ tar --help
GNU“tar”将许多文件保存到一个磁带或磁盘归档文件中,
并可以从归档文件中恢复各个文件。

用法:tar [选项]... [文件]...

示例:
  tar -cf archive.tar foo bar  # 从文件 foo 和 bar 创建归档文件 archive.tar。
  tar -tvf archive.tar         # 详细列举归档文件 archive.tar 中的所有文件。
  tar -xf archive.tar          # 解析归档文件 archive.tar 中的所有文件。

如果长选项表明参数是必需的,那么对等价的短选项
来说它同样是必需的。对可选的参数来说也类似。

主要操作模式:
  -t, --list              列出归档文件内容目录
  -x, --extract, --get    从归档文件中解析文件
  -c, --create            创建新的归档文件
  -d, --diff, --compare   找出归档文件和文件系统的不同之处
  -r, --append            将文件附加到归档文件之后
  -u, --update            只附加比归档中新的文件
  -A, --catenate          将 tar 文件附加到归档文件之后
      --concatenate       与 -A 相同
      --delete            从归档文件中删除 (不能在磁带上!)

Operation modifiers:
  -W, --verify               attempt to verify the archive after writing it
      --remove-files         remove files after adding them to the archive
  -k, --keep-old-files       don't replace existing files when extracting
      --overwrite            overwrite existing files when extracting
      --no-overwrite-dir     preserve metadata of existing directories
  -U, --unlink-first         remove each file prior to extracting over it
      --recursive-unlink     empty hierarchies prior to extracting directory
  -S, --sparse               handle sparse files efficiently
  -O, --to-stdout            extract files to standard output
  -G, --incremental          handle old GNU-format incremental backup
  -g, --listed-incremental=FILE
                             handle new GNU-format incremental backup
      --ignore-failed-read   do not exit with nonzero on unreadable files
      --occurrence[=NUM]     process only the NUMth occurrence of each file in
                             the archive. This option is valid only in
                             conjunction with one of the subcommands --delete,
                             --diff, --extract or --list and when a list of
                             files is given either on the command line or
                             via -T option.
                             NUM defaults to 1.

处理文件属性:
      --owner=NAME             将被添加的文件所有者设置为 NAME
      --group=NAME             将被添加的文件所属的组设置为 NAME
      --mode=CHANGES           将被添加的文件的属性设置为 CHANGES
      --atime-preserve         不要改变输出文件的访问时间
  -m, --modification-time      不要解析文件的修改时间
      --same-owner             试图以相同的所有权解析文件
      --no-same-owner          以您自己的身份解析文件
      --numeric-owner          总是用编号作为用户/组的名字
  -p, --same-permissions       解析许可权限信息
      --no-same-permissions    不要解析许可权限信息
      --preserve-permissions   与 -p 相同
  -s, --same-order             对要解析的名称进行排序以便与归档匹配
      --preserve-order         与 -s 相同
      --preserve               与 -p 和 -s 都相同

设备选择与切换:
  -f, --file=ARCHIVE             使用归档文件或设备 ARCHIVE
      --force-local              即使含有冒号,归档文件也是本地文件
      --rsh-command=COMMAND      用远程 COMMAND 代替 rsh
  -[0-7][lmh]                    指定驱动器和密度
  -M, --multi-volume             创建/列举/解析多卷归档文件
  -L, --tape-length=NUM          在写入 NUM x 1024 个字节后更换磁带
  -F, --info-script=FILE         在每个磁带末端运行脚本 (隐含 -M)
      --new-volume-script=FILE   与 -F FILE 相同
      --volno-file=FILE          使用/更新 FILE 中的卷编号

设备分块:
  -b, --blocking-factor=BLOCKS   每个记录 BLOCKS x 512 个字节
      --record-size=SIZE         每个记录 SIZE 个字节,512 的倍数
  -i, --ignore-zeros             忽略归档中全为零的块 (标示文件结束)
  -B, --read-full-records        当我们读入时重新分块 (为 4.2BSD 管道提供)

Archive format selection:
      --format=FMTNAME               create archive of the given format.
                                     FMTNAME is one of the following:
                                     v7        old V7 tar format
                                     oldgnu    GNU format as per tar <= 1.12
                                     gnu       GNU tar 1.13 format
                                     ustar     POSIX 1003.1-1988 (ustar) format
                                     posix     POSIX 1003.1-2001 (pax) format
      --old-archive, --portability   same as --format=v7
      --posix                        same as --format=posix
  --pax-option keyword[[:]=value][,keyword[[:]=value], ...]
                                     control pax keywords
  -V, --label=NAME                   create archive with volume name NAME
              PATTERN                at list/extract time, a globbing PATTERN
  -j, --bzip2                        filter the archive through bzip2
  -z, --gzip, --ungzip               filter the archive through gzip
  -Z, --compress, --uncompress       filter the archive through compress
      --use-compress-program=PROG    filter through PROG (must accept -d)

Local file selection:
  -C, --directory=DIR          change to directory DIR
  -T, --files-from=NAME        get names to extract or create from file NAME
      --null                   -T reads null-terminated names, disable -C
      --exclude=PATTERN        exclude files, given as a PATTERN
  -X, --exclude-from=FILE      exclude patterns listed in FILE
      --anchored               exclude patterns match file name start (default)
      --no-anchored            exclude patterns match after any /
      --ignore-case            exclusion ignores case
      --no-ignore-case         exclusion is case sensitive (default)
      --wildcards              exclude patterns use wildcards (default)
      --no-wildcards           exclude patterns are plain strings
      --wildcards-match-slash  exclude pattern wildcards match '/' (default)
      --no-wildcards-match-slash exclude pattern wildcards do not match '/'
  -P, --absolute-names         don't strip leading `/'s from file names
  -h, --dereference            dump instead the files symlinks point to
      --no-recursion           avoid descending automatically in directories
  -l, --one-file-system        stay in local file system when creating archive
  -K, --starting-file=NAME     begin at file NAME in the archive
      --strip-path=NUM         strip NUM leading components from file names
                               before extraction
  -N, --newer=DATE-OR-FILE     only store files newer than DATE-OR-FILE
      --newer-mtime=DATE       compare date and time when data changed only
      --after-date=DATE        same as -N
      --backup[=CONTROL]       在删除前备份,选择版本控制
      --suffix=SUFFIX          在删除前备份,覆盖常用后缀

Informative output:
      --help            print this help, then exit
      --version         print tar program version number, then exit
  -v, --verbose         verbosely list files processed
      --checkpoint      print directory names while reading the archive
      --check-links     print a message if not all links are dumped
      --totals          print total bytes written while creating archive
      --index-file=FILE send verbose output to FILE
  -R, --block-number    show block number within archive with each message
  -w, --interactive     ask for confirmation for every action
      --confirmation    same as -w

Compatibility options:
  -o                                 when creating, same as --old-archive
                                     when extracting, same as --no-same-owner

除非以 --suffix 或 SIMPLE_BACKUP_SUFFIX 设置备份后缀,否则备份后缀就是“~”。
可以用 --backup 或 VERSION_CONTROL 设置版本控制,可能的值为:

  t, numbered     进行编号备份
  nil, existing   如果编号备份存在则进行编号备份,否则进行简单备份
  never, simple   总是使用简单备份
ARCHIVE may be FILE, HOST:FILE or USER@HOST:FILE; DATE may be a textual date
or a file name starting with `/' or `.', in which case the file's date is used.
*This* `tar' defaults to `--format=gnu -f- -b20'.

Report bugs to <bug-tar@gnu.org>.
....


[/php]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表