简体   繁体   English

从特定文件夹中的所有tar文件中提取特定文件类型

[英]Extracting specific file types from all tar files from specific folder

I need shell script which accept two arguments. 我需要接受两个参数的shell脚本。 First one is path to the specific folder and second one is int value (1 or 2). 第一个是指向特定文件夹的路径,第二个是int值(1或2)。

If second argument is 1 then I have to go through all tar files in mentioned folder and extract just executable files into specific folder inside path from first argument. 如果第二个参数为1,那么我必须遍历提到的文件夹中的所有tar文件,并将可执行文件仅提取到第一个参数的路径内的特定文件夹中。 in this case name of that folder is "unpacked". 在这种情况下,该文件夹的名称为“ unpacked”。

If second argument is 2 then I have to extract all *.txt files from all tar files from folder given by first argument. 如果第二个参数是2,那么我必须从第一个参数给定的文件夹中的所有tar文件中提取所有*.txt文件。

I am trying something like this but don't know how to catch every tar file and extract one of these two file types. 我正在尝试类似的操作,但不知道如何捕获每个tar文件并提取这两种文件类型之一。

#!/bin/bash

cd $1
if [$2 –eq 1 ]
then
for f in *.tar; do
tar –xv –f "$f" –-wildcards EXECUTABLE FILES -C ./unpacked
done
fi

if [$2 –eq 2 ]
then
for f in *.tar; do
tar –xv –f "$f" –-wildcards "*.txt" -C ./unpacked
done
fi

The [MEMBER...] argument must come last. [MEMBER...]参数必须位于最后。

#!/bin/bash

cd $1
if [$2 –eq 1 ]
then
for f in *.tar; do
tar –xv –f "$f" –-wildcards -C ./unpacked EXECUTABLE FILES
done
fi

if [$2 –eq 2 ]
then
for f in *.tar; do
tar –xv –f "$f" –-wildcards -C ./unpacked "*.txt"
done
fi

要从tar文件中提取特定文件,请在您的终端中执行:

$ tar -zxvf TARNAME.tar.gz PATH/FILNAME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从多个.tar.gz文件中提取特定文件名以构建一个.csv文件 - Extracting a specific file name from multiple .tar.gz files to build one .csv file 从tar文件中提取特定目录而不创建包含层次结构 - extracting specific dir from tar file without creating the containing hierarchy 从tar.gz中将特定文件夹解压缩到特定目录 - Extract a specific folder to specific directory from a tar.gz 留在另一个文件夹中,如何从另一个目录中压缩特定文件? - Staying in another folder, how can i tar specific files from another directory? 使用 wget 命令从 tar.gz 文件下载特定文件夹 - Download specific folder from tar.gz file using wget command tar 文件夹并排除所有子文件夹,然后 tar 到特定路径 - tar folder and exclude all subfolders, then tar to specific path 从文件夹中的所有文件中提取 200 行 - Extracting 200 lines from all the files in a folder 如何从文件夹中的所有文件中删除带有特定字符串的行 - How to remove from all files in folder the lines with specific string 从 Ansible Playbook 中删除服务器所有目录中的特定文件夹/文件 - Delete specific folder/files in all the directories of the server from the Ansible Playbook 在Linux上使用sed输出的特定文件列表创建tar gz - Create tar gz on linux with specific list of files from sed output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM