我有一个要求,比如我必须从像
这样的文件夹中创建焦油"/xyz/test1/abc1/"
"/xyz/test1/abc2/"
"/xyz/test3/abc3/"
我必须在每个相应的目录中创建abc1.tar
,abc2.tar
,abc3.tar
等目录并复制到~/tmp
目录,任何bash脚本都可以帮助我。我有16个这样的文件夹。
答案 0 :(得分:0)
我们可以将所有 abc 目录与下面的
连接起来tar -cvf abc.tar /xyz/test*/abc*
如果需要单独的tar文件,那么
cat DirList.txt
/xyz/test1
/xyz/test2
/xyz/test3
将目录列表提供给循环,
i=1 // **i** - variable to to make the file names unique
while read dirName
do
cd ${dirName} // --> change directory
tar -cvf abc${i}.tar abc${i} // --> tar abc directory
mv abc.tar /tmp // --> move tar file to /tmp
i=$(expr $i + 1) //--> increase variable i by one for next iteration.
done < DirList.txt
答案 1 :(得分:0)
@JithinScaria请在下面找到我的问题
我有以下要求我需要在执行以下操作后为多个应用程序进行构建
Git克隆,git获取并使用shell脚本构建maven .-&gt;所有这些都是用shell脚本处理的。
应用程序目录如下所示
$ / artifactserver / COM / XYZ / ABC /
ls -lrt
应用1 /
应用2 /
APP3 /
App4 /
直到
App16 /
cd App1 / target /
tar -cvf App1Home.tar App1Home /
cp -r App1Home.tar / tmp
cd ../ ..
cd App2 / target /
tar -cvf App2Home.tar App2Home /
cp -r App2Home.tar / tmp
cd ../..
等等 如何实现所有这些.tars并将它们复制到/ tmp with block。
答案 2 :(得分:0)
我希望下面的任何一个都能完成你的工作,
选项1:
创建一个包含 16 目录列表的文件,如下所示,
Value
使用此文件作为下面while循环的输入,
<!DOCTYPE html>
<html><head>
<title>Title of the document</title>
</head>
<body>
Content of the document......
</body>
</html>
选项2:
使用 16 目录列表创建一个文件,tar文件名和目录名称用分隔符进行涂焦,这里我使用$cat DirList.txt
/artifactserver/com/xyz/abc/App1/target/
/artifactserver/com/xyz/abc/App2/target/
/artifactserver/com/xyz/abc/App3/target/
...
/artifactserver/com/xyz/abc/App16/target/
作为分隔符
i=1 // **i** - incremental variable
while read dirName
do
cd ${dirName} # --> change directory
tar -cvf App${i}Home.tar App${i}Home/ # --> tar directory
cp App${i}Home.tar /tmp # --> copy tar file to /tmp
i=$(expr $i + 1) # --> increase variable i by one.
done < DirList.txt
使用此文件作为下面while循环的输入,
|