我有一个名为tar的tar文件_home_rock_files.tar
,该文件已在源服务器中挂载,现在将这个tar复制到目标服务器后,其目录结构与相同_home_rock_files
。现在,我的问题在这里出现。
我想编写一个shell脚本,将脚本自动解压缩_home_rock_files.tar
并将其解压缩到/home/rock/files/
;目的地路径是在这样的文件名中指定的。
我想出了这套bash命令:
[sudo] find * -type f -name "SPECIFY THE FILE NAME"|
while read FILE ; do # read the files
destpath="$(echo "$FILE"| sed 's/_/\//g;s/.tar//')"; #rerplace all _s with /s and drop the .tar ext to achive destpath
mkdir -p "$destpath"; #create the directory path of despath
tar xzf "$FILE" -C "$destpath" ; #untar the file to destpath
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句