command line - Untar files to destination directories based on tar file names - Ask Ubuntu


i have tar file named _home_rock_files.tar tarred in source server , once copied tar destination server have same directory structure _home_rock_files. now, question arises here.

i want write shell script automatically untars _home_rock_files.tar , untars archive /home/rock/files/; destination path specified in file name this.

i came set of bash commands:

[sudo] find * -type f -name "specify file name"|      while read file ;       # read files         destpath="$(echo "$file"| sed 's/_/\//g;s/.tar//')"; #rerplace _s /s , drop .tar ext achive destpath         mkdir -p "$destpath";  #create directory path of despath           tar xzf "$file" -c "$destpath" ;  #untar file destpath     done 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User