【问题标题】:Is it possible to extract the contents of a tar file to two directories at the same time with a single command?是否可以使用单个命令同时将 tar 文件的内容提取到两个目录?
【发布时间】:2022-01-08 16:49:00
【问题描述】:

我很好奇的是我是否可以使用命令的一个版本 tar -xvf fileName.tar 来完成这个。

【问题讨论】:

    标签: linux scripting


    【解决方案1】:

    我推荐使用这个脚本。

    #!/bin/bash
    mkdir ./directory0
    mkdir ./directory1
    path="directory"
    for catalog in ./"$path"*
    do
      tar -xvf fileName.tar -C $catalog
    done
    

    【讨论】:

    • 看起来很有趣。
    • 不能在文件名后面也指定目录吗?
    • @Sofia190,如您所知,命令tar 具有下一个语法tar [key-parameters] [archive-file] [file or directory to be archived]。要提取 tar 文件,只需使用关键参数 x(提取)发出以下命令。例如,以下命令将在具体目录directory0 中提取文件fileName.taruser@userdesktop:~$ tar -xvf fileName.tar -C ./directory0。如果要在具体目录中提取文件,请使用关键参数-C(指定目录)。
    • 我正在考虑编写脚本的许多变体。
    • 可能目录存在。
    猜你喜欢
    • 2011-04-29
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2016-05-01
    相关资源
    最近更新 更多