[英]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.