let's have bunch of *.tar.gz files located in hierarchy of folders. way find files, , execute multiple commands on it.
i know if need execute 1 command on target file, can use this:
$ find . -name "*.tar.gz" -exec tar xvzf {} \; but if need execute multiple commands on target file? must write bash script here, or there simpler way?
samples of commands need executed a.tar.gz file:
$ tar xvzf a.tar.gz # assume untars folder logs $ mv logs logs_a $ rm a.tar.gz
here's works me (thanks etan reisner suggestions)
#!/bin/bash # target folder (to search tar.gz files) parsed command line find $1 -name "*.tar.gz" -print0 | while ifs= read -r -d '' file; # magic of getting each tar.gz file , assign shell variable `file` echo $file # can `file` variable tar xvzf $file # mv untar_folder $file.suffix # untar_folder name of folder after untar rm $file done as suggested, the array way unsafe if file name contained space(s), , doesn't seem work in case.
Comments
Post a Comment