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

nvidia - NV18 [GeForce4 MX 4000] driver - Ask Ubuntu

drivers - No wi-fi network after install - Ask Ubuntu