Link
asked on
simple bash script needed to unpack tar.gz
I have a series of commands I use to unpack a tar.gz file.
Lets say this file is xxxx.tar.gz. Here are the following commands:
gunzip xxxx.tar.gz
tar xvf xxxx.tar
cd xxxx
gunzip *.tgz
for a in *.tar
do
tar xvf $a
done
rm *.tar
rm -rf wirespeed
rm -rf database
cd linuxLogs
gunzip *.gz
cd ../closedfire
gunzip asp_saved_logs.tgz
tar xvf asp_saved_logs.tar
rm *.tar
cd ../tailf
gunzip tailf_saved_logs.tgz
tar xvf tailf_saved_logs.tar
rm *.tar
cd ../np
gunzip np_saved_logs.tgz
tar xvf np_saved_logs.tar
rm *.tar
cd ..
pwd
find ./ -type f | xargs grep "CRITICAL"
I now cut and paste the entire set of commands into my bash window.
Every time I have a new different tar.gz file I need to replace the xxxx with the new file name then cut/paste all the commands again.
I would like to place all the commands in a script named "unpack" and then just use it at the command line with the new filename
like
bash$ unpack filename10.tar.gz
Currently I cut/paste the beginning part of the tar.gz file name (say zzzzwith xxxx above, then paste the entire series into my bash window where the tar.gz is.
Lets say this file is xxxx.tar.gz. Here are the following commands:
gunzip xxxx.tar.gz
tar xvf xxxx.tar
cd xxxx
gunzip *.tgz
for a in *.tar
do
tar xvf $a
done
rm *.tar
rm -rf wirespeed
rm -rf database
cd linuxLogs
gunzip *.gz
cd ../closedfire
gunzip asp_saved_logs.tgz
tar xvf asp_saved_logs.tar
rm *.tar
cd ../tailf
gunzip tailf_saved_logs.tgz
tar xvf tailf_saved_logs.tar
rm *.tar
cd ../np
gunzip np_saved_logs.tgz
tar xvf np_saved_logs.tar
rm *.tar
cd ..
pwd
find ./ -type f | xargs grep "CRITICAL"
I now cut and paste the entire set of commands into my bash window.
Every time I have a new different tar.gz file I need to replace the xxxx with the new file name then cut/paste all the commands again.
I would like to place all the commands in a script named "unpack" and then just use it at the command line with the new filename
like
bash$ unpack filename10.tar.gz
Currently I cut/paste the beginning part of the tar.gz file name (say zzzzwith xxxx above, then paste the entire series into my bash window where the tar.gz is.
If you don't want to proceed as suggested above you can replace "xxx" with ${file} then issue
export file=filename
Now copy and paste as usual.
export file=filename
Now copy and paste as usual.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was easy, Thanks!
/path/to/myunpack.sh filename
where filename means the name of the desired file and "/path/to/..." means the location of the new file.