AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1168158
Accepted
An Ignorant Wanderer
An Ignorant Wanderer
Asked: 2019-08-25 03:12:13 +0800 CST2019-08-25 03:12:13 +0800 CST 2019-08-25 03:12:13 +0800 CST

tar 使用短格式选项与旧样式

  • 772

在 GNU 手册中tar,有以下示例表明选项的顺序很重要:

tar -cfv collection.tar blues folk jazz

在这种情况下,因为v放在 之后f,那么 tar 存档将被命名为“v”,并且如果它存在于当前目录中,tar将尝试添加到存档中。collection.tar但是,如果我从一开始就省略了-,那么该命令会按照我们的意愿工作,尽管它v被放置在f. 为什么?

command-line tar
  • 2 2 个回答
  • 191 Views

2 个回答

  • Voted
  1. Best Answer
    Thomas
    2019-08-25T03:39:15+08:002019-08-25T03:39:15+08:00

    因为这是不同选项样式的工作方式,它们的行为也不同。


    手册页说明UNIX 或 short-option style,以单个破折号为前缀。

    任何数量的不带参数的选项都可以在一个破折号之后聚集在一起,例如 -vkp。带参数的选项(无论是强制的还是可选的)可以出现在这样的集群的末尾,例如 -vkpf a.tar。


    传统样式选项 style,没有破折号的样式:

    在传统风格中,第一个参数是一组选项字母,所有后续参数都为需要它们的选项提供参数。参数的读取顺序与选项字母的顺序相同。处理完所有选项后保留的任何命令行字都被视为非可选参数:文件或存档成员名称。


    如您所见,UNIX 或短选项样式要求选项的参数直接在选项之后。
    而传统风格的选项风格需要一组选项和合适的参数以正确的顺序排列选项。

    • 5
  2. Arkadiusz Drabczyk
    2019-08-25T03:40:39+08:002019-08-25T03:40:39+08:00

    它清楚地描述在man tar:

    选项样式

       Options to GNU tar can be given in three different styles.  In
       traditional style, the first argument is a cluster of option
       letters and all subsequent arguments supply arguments to those
       options that require them.  The arguments are read in the same
       order as the option letters.  Any command line words that
       remain after all options has been processed are treated as
       non-optional arguments: file or archive member names.
    
       For example, the c option requires creating the archive, the v
       option requests the verbose operation, and the f option takes
       an argument that sets the name of the archive to operate upon.
       The following command, written in the traditional style,
       instructs tar to store all files from the directory /etc into
       the archive file etc.tar verbosely listing the files being
       archived:
    
       tar cfv a.tar /etc
    

    所以在这种情况下:

    tar cfv collection.tar blues folk jazz
    

    collection.tar是一个参数,f其余blues folk jazz参数被视为存档成员名称。

    • 4

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve