Hi,

I continue with Unix commands concerning archiving ZIP, TAR…etc.

First, we list the content of current folder /opt/tomcat/webapps/host-manager:

huo@myserver:/opt/tomcat/webapps/host-manager>ls -lR
.:
total 20
drwxr-xr-x 2 huoadmin huoadmin 4096 2014-01-06 10:18 images
-rw-r--r-- 1 huoadmin huoadmin  889 2013-07-02 09:59 index.jsp
-rw-r--r-- 1 huoadmin huoadmin 1103 2013-07-02 09:59 manager.xml
drwxr-xr-x 2 huoadmin huoadmin 4096 2014-01-06 10:18 META-INF
drwxr-xr-x 3 huoadmin huoadmin 4096 2014-01-06 10:18 WEB-INF

./images:
total 40
-rw-r--r-- 1 huoadmin huoadmin 1037 2013-07-02 09:59 add.gif
-rw-r--r-- 1 huoadmin huoadmin 7279 2013-07-02 09:59 asf-logo.gif
-rw-r--r-- 1 huoadmin huoadmin  394 2013-07-02 09:59 code.gif
-rw-r--r-- 1 huoadmin huoadmin  608 2013-07-02 09:59 design.gif
-rw-r--r-- 1 huoadmin huoadmin  261 2013-07-02 09:59 docs.gif
-rw-r--r-- 1 huoadmin huoadmin  345 2013-07-02 09:59 fix.gif
-rw-r--r-- 1 huoadmin huoadmin 1934 2013-07-02 09:59 tomcat.gif
-rw-r--r-- 1 huoadmin huoadmin  627 2013-07-02 09:59 update.gif
-rw-r--r-- 1 huoadmin huoadmin   43 2013-07-02 09:59 void.gif

./META-INF:
total 4
-rw-r--r-- 1 huoadmin huoadmin 1191 2013-07-02 09:59 context.xml

./WEB-INF:
total 12
drwxr-xr-x 2 huoadmin huoadmin 4096 2014-01-06 10:18 jsp
-rw-r--r-- 1 huoadmin huoadmin 4838 2013-07-02 09:59 web.xml

./WEB-INF/jsp:
total 12
-rw-r--r-- 1 huoadmin huoadmin 2833 2013-07-02 09:59 401.jsp
-rw-r--r-- 1 huoadmin huoadmin 3592 2013-07-02 09:59 403.jsp
-rw-r--r-- 1 huoadmin huoadmin 4838 2013-07-02 09:59 404.jsp

Archive a folder in TAR.GZ

huo@myserver:/opt/tomcat/webapps>tar cf - ./host-manager/ | gzip -c > /tmp/HUO/host-manager.tar.gz

huo@myserver:/opt/tomcat/webapps>ls -lR /tmp/HUO/
/tmp/HUO/:
total 16
-rw-r--r-- 1 huoadmin huoadmin 15438 2014-02-10 16:49 host-manager.tar.gz

Check the content in TAR.GZ archive

huo@myserver:/tmp/HUO>gunzip -c /tmp/HUO/host-manager.tar.gz | tar tf - 
./host-manager/
./host-manager/manager.xml
./host-manager/index.jsp
./host-manager/WEB-INF/
./host-manager/WEB-INF/jsp/
./host-manager/WEB-INF/jsp/404.jsp
./host-manager/WEB-INF/jsp/401.jsp
./host-manager/WEB-INF/jsp/403.jsp
./host-manager/WEB-INF/web.xml
./host-manager/META-INF/
./host-manager/META-INF/context.xml
./host-manager/images/
./host-manager/images/add.gif
./host-manager/images/fix.gif
./host-manager/images/docs.gif
./host-manager/images/code.gif
./host-manager/images/void.gif
./host-manager/images/design.gif
./host-manager/images/asf-logo.gif
./host-manager/images/update.gif
./host-manager/images/tomcat.gif

Unarchive a TAR.GZ archive in a folder

huo@myserver:/tmp/HUO>gunzip -c /tmp/HUO/host-manager.tar.gz | tar xf - 

huo@myserver:/tmp/HUO>ll
total 20
drwxr-xr-x 5 huoadmin huoadmin  4096 2014-01-06 10:18 host-manager
-rw-r--r-- 1 huoadmin huoadmin 15438 2014-02-10 17:00 host-manager.tar.gz

huo@myserver:/tmp/HUO>ls -lR
.:
total 20
drwxr-xr-x 5 huoadmin huoadmin  4096 2014-01-06 10:18 host-manager
-rw-r--r-- 1 huoadmin huoadmin 15438 2014-02-10 17:00 host-manager.tar.gz

./host-manager:
total 20
drwxr-xr-x 2 huoadmin huoadmin 4096 2014-01-06 10:18 images
-rw-r--r-- 1 huoadmin huoadmin  889 2013-07-02 09:59 index.jsp
-rw-r--r-- 1 huoadmin huoadmin 1103 2013-07-02 09:59 manager.xml
drwxr-xr-x 2 huoadmin huoadmin 4096 2014-01-06 10:18 META-INF
drwxr-xr-x 3 huoadmin huoadmin 4096 2014-01-06 10:18 WEB-INF

./host-manager/images:
total 40
-rw-r--r-- 1 huoadmin huoadmin 1037 2013-07-02 09:59 add.gif
-rw-r--r-- 1 huoadmin huoadmin 7279 2013-07-02 09:59 asf-logo.gif
-rw-r--r-- 1 huoadmin huoadmin  394 2013-07-02 09:59 code.gif
-rw-r--r-- 1 huoadmin huoadmin  608 2013-07-02 09:59 design.gif
-rw-r--r-- 1 huoadmin huoadmin  261 2013-07-02 09:59 docs.gif
-rw-r--r-- 1 huoadmin huoadmin  345 2013-07-02 09:59 fix.gif
-rw-r--r-- 1 huoadmin huoadmin 1934 2013-07-02 09:59 tomcat.gif
-rw-r--r-- 1 huoadmin huoadmin  627 2013-07-02 09:59 update.gif
-rw-r--r-- 1 huoadmin huoadmin   43 2013-07-02 09:59 void.gif

./host-manager/META-INF:
total 4
-rw-r--r-- 1 huoadmin huoadmin 1191 2013-07-02 09:59 context.xml

./host-manager/WEB-INF:
total 12
drwxr-xr-x 2 huoadmin huoadmin 4096 2014-01-06 10:18 jsp
-rw-r--r-- 1 huoadmin huoadmin 4838 2013-07-02 09:59 web.xml

./host-manager/WEB-INF/jsp:
total 12
-rw-r--r-- 1 huoadmin huoadmin 2833 2013-07-02 09:59 401.jsp
-rw-r--r-- 1 huoadmin huoadmin 3592 2013-07-02 09:59 403.jsp
-rw-r--r-- 1 huoadmin huoadmin 4838 2013-07-02 09:59 404.jsp

Archive each element (subfolder, file) of root folder in TAR.GZ
In this example, we will create a TAR.GZ archive for each element (folder or file) contained in a root folder. The archives’ names will be the name of element suffixed by “.tar.gz”. So to do this, we create a shellscript file named “createMultipleArchives.sh”.

huo@myserver:/tmp/HUO>more ./createMultipleArchives.sh
cd /opt/tomcat/webapps/host-manager
for f in * ; do
       tar cf - $f | gzip -c > /tmp/HUO/${f}.tar.gz
done

huo@myserver:/tmp/HUO>./createMultipleArchives.sh

huo@myserver:/tmp/HUO>ll

huo@myserver:/opt/tomcat/webapps>tar cf - ./host-manager/ | gzip -c > /tmp/HUO/host-manager.tar.gz
total 32
-rw-r--r-- 1 huoadmin huoadmin 11538 2014-02-11 09:51 images.tar.gz
-rw-r--r-- 1 huoadmin huoadmin   660 2014-02-11 09:51 index.jsp.tar.gz
-rw-r--r-- 1 huoadmin huoadmin   788 2014-02-11 09:51 manager.xml.tar.gz
-rwxr-xr-x 1 huoadmin huoadmin   121 2014-02-11 09:51 createMultipleArchives.sh
-rw-r--r-- 1 huoadmin huoadmin  3275 2014-02-11 09:51 WEB-INF.tar.gz

That’s all!!!

Huseyin OZVEREN