how to extract single Folder / File from .tar.gz
how to extract single Folder / File from .tar.gz
Dear Expert
I am cracking my head but no success.
there are three question as below
how to view tar.gz to view files (all files including rrd xml) I tried as below but no success (not showing any rrd/xml files)
tar -ztvf nagiosxi.123456789.tar.gz
how to extract one full folder of /usr/local/nagios/share/perfdata/mydevice-7600/
how to extract single file /usr/local/nagios/share/perfdata/mydevice-7600/GigabitEthernet0_2.1234_Bandwidth.rrd
regards
I am cracking my head but no success.
there are three question as below
how to view tar.gz to view files (all files including rrd xml) I tried as below but no success (not showing any rrd/xml files)
tar -ztvf nagiosxi.123456789.tar.gz
how to extract one full folder of /usr/local/nagios/share/perfdata/mydevice-7600/
how to extract single file /usr/local/nagios/share/perfdata/mydevice-7600/GigabitEthernet0_2.1234_Bandwidth.rrd
regards
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: how to extract single Folder / File from .tar.gz
Assuming nagiosxi.123456789.tar.gz is the backup file, run
to extract a dir
to extract the file
These files/directories will be placed in their path under where you are running the command, so if you run this from your home directory you would be able to view the file as:
Code: Select all
backupfile=/store/backups/nagiosxi/nagiosxi.123456789.tar.gzCode: Select all
tar -xzOf $backupfile $(basename $backupfile .tar.gz)/nagios.tar.gz | tar -xzf - usr/local/nagios/share/perfdata/mydevice-7600Code: Select all
tar -xzOf $backupfile $(basename $backupfile .tar.gz)/nagios.tar.gz | tar -xzf - usr/local/nagios/share/perfdata/mydevice-7600/GigabitEthernet0_2.1234_Bandwidth.rrdCode: Select all
ls -l ~/usr/local/nagios/share/perfdata/mydevice-7600/GigabitEthernet0_2.1234_Bandwidth.rrdRe: how to extract single Folder / File from .tar.gz
Dear Scott
Thanks for your detail reply Thanks its working fine, God bless u.
but very first question you omitted to reply.....how to list all zip files/folder in the main NagiosXi .tar.gz file? (just to list all files/folders inside .tar.gz)
Regards
Thanks for your detail reply Thanks its working fine, God bless u.
but very first question you omitted to reply.....how to list all zip files/folder in the main NagiosXi .tar.gz file? (just to list all files/folders inside .tar.gz)
Regards
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: how to extract single Folder / File from .tar.gz
Sorry I missed thatzaji_nms wrote:Dear Scott
Thanks for your detail reply Thanks its working fine, God bless u.
but very first question you omitted to reply.....how to list all zip files/folder in the main NagiosXi .tar.gz file? (just to list all files/folders inside .tar.gz)
Regards
Code: Select all
tar -ztvf /store/backups/nagiosxi/nagiosxi.123456789.tar.gzRe: how to extract single Folder / File from .tar.gz
Dear Scott
no, no its not working, in my very first post in this thread, i already mentioned, its just showing this
pwd
/tmp
tar -ztvf nagiosxi.123456789.tar.gz | more
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/
-rw-r--r-- nagios/users 2781800623 2222-22-22 05:09 nagiosxi.123456789/nagios.tar.gz
-rw-r--r-- nagios/users 3004779 2222-22-22 05:09 nagiosxi.123456789/nagvis.tar.gz
-rw-r--r-- nagios/users 901842 2222-22-22 04:59 nagiosxi.123456789/nagiosql.tar.gz
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/httpd/
-rw-r--r-- nagios/users 427 2222-22-22 10:05 nagiosxi.123456789/httpd/nagiosql.conf
-rw-r--r-- nagios/users 1010 2222-22-22 16:46 nagiosxi.123456789/httpd/nagios.conf
-rw-r--r-- nagios/users 601 2222-22-22 10:05 nagiosxi.123456789/httpd/nagiosxi.conf
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/logrotate/
-rw-r--r-- nagios/users 63 2222-22-22 13:19 nagiosxi.123456789/logrotate/nagiosxi
-rw-r--r-- nagios/users 20732817 2222-22-22 05:09 nagiosxi.123456789/nrdp.tar.gz
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/pgsql/
-rw-r--r-- nagios/users 7825867 2222-22-22 05:09 nagiosxi.123456789/pgsql/nagiosxi.sql
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/mysql/
-rw-r--r-- nagios/users 5619213 2222-22-22 05:09 nagiosxi.123456789/mysql/nagiosql.sql
-rw-r--r-- nagios/users 175136707 2222-22-22 05:09 nagiosxi.123456789/mysql/nagios.sql
-rw-r--r-- nagios/users 195 2222-22-22 04:59 nagiosxi.123456789/nagiosql-etc.tar.gz
-rw-r--r-- nagios/users 2917560 2222-22-22 05:09 nagiosxi.123456789/mrtg.cfg
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/conf.d/
-rw-r--r-- nagios/users 67344 2222-22-22 05:09 nagiosxi.123456789/conf.d/onetwo.cfg
-rw-r--r-- nagios/users 992 2222-22-22 05:09 nagiosxi.123456789/conf.d/onetwothree_517.cfg
-------------------------------omitted some output-----------------------------
-rw-r--r-- nagios/users 999 2222-22-22 05:09 nagiosxi.123456789/conf.d/fourfive_10602.cfg
-rw-r--r-- nagios/users 967 2222-22-22 05:09 nagiosxi.123456789/conf.d/sixseven_504.cfg
-rw-r--r-- nagios/users 1047 2222-22-22 05:09 nagiosxi.123456789/conf.d/eightnine_10.cfg
-rw-r--r-- nagios/users 67755134 2222-22-22 05:09 nagiosxi.123456789/nagiosxi.tar.gz
-rw-r--r-- nagios/users 26194 2222-22-22 05:09 nagiosxi.123456789/hosts
-------------------------------------------------
i think it will work in two section basefile and then redirect as you mentioned in your solution
also can you please reply (solution) if i want to list files/folder
with FULL PATH
without FULL PATH (just filenames)
Regards
no, no its not working, in my very first post in this thread, i already mentioned, its just showing this
pwd
/tmp
tar -ztvf nagiosxi.123456789.tar.gz | more
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/
-rw-r--r-- nagios/users 2781800623 2222-22-22 05:09 nagiosxi.123456789/nagios.tar.gz
-rw-r--r-- nagios/users 3004779 2222-22-22 05:09 nagiosxi.123456789/nagvis.tar.gz
-rw-r--r-- nagios/users 901842 2222-22-22 04:59 nagiosxi.123456789/nagiosql.tar.gz
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/httpd/
-rw-r--r-- nagios/users 427 2222-22-22 10:05 nagiosxi.123456789/httpd/nagiosql.conf
-rw-r--r-- nagios/users 1010 2222-22-22 16:46 nagiosxi.123456789/httpd/nagios.conf
-rw-r--r-- nagios/users 601 2222-22-22 10:05 nagiosxi.123456789/httpd/nagiosxi.conf
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/logrotate/
-rw-r--r-- nagios/users 63 2222-22-22 13:19 nagiosxi.123456789/logrotate/nagiosxi
-rw-r--r-- nagios/users 20732817 2222-22-22 05:09 nagiosxi.123456789/nrdp.tar.gz
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/pgsql/
-rw-r--r-- nagios/users 7825867 2222-22-22 05:09 nagiosxi.123456789/pgsql/nagiosxi.sql
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/mysql/
-rw-r--r-- nagios/users 5619213 2222-22-22 05:09 nagiosxi.123456789/mysql/nagiosql.sql
-rw-r--r-- nagios/users 175136707 2222-22-22 05:09 nagiosxi.123456789/mysql/nagios.sql
-rw-r--r-- nagios/users 195 2222-22-22 04:59 nagiosxi.123456789/nagiosql-etc.tar.gz
-rw-r--r-- nagios/users 2917560 2222-22-22 05:09 nagiosxi.123456789/mrtg.cfg
drwxr-xr-x nagios/users 0 2222-22-22 05:09 nagiosxi.123456789/conf.d/
-rw-r--r-- nagios/users 67344 2222-22-22 05:09 nagiosxi.123456789/conf.d/onetwo.cfg
-rw-r--r-- nagios/users 992 2222-22-22 05:09 nagiosxi.123456789/conf.d/onetwothree_517.cfg
-------------------------------omitted some output-----------------------------
-rw-r--r-- nagios/users 999 2222-22-22 05:09 nagiosxi.123456789/conf.d/fourfive_10602.cfg
-rw-r--r-- nagios/users 967 2222-22-22 05:09 nagiosxi.123456789/conf.d/sixseven_504.cfg
-rw-r--r-- nagios/users 1047 2222-22-22 05:09 nagiosxi.123456789/conf.d/eightnine_10.cfg
-rw-r--r-- nagios/users 67755134 2222-22-22 05:09 nagiosxi.123456789/nagiosxi.tar.gz
-rw-r--r-- nagios/users 26194 2222-22-22 05:09 nagiosxi.123456789/hosts
-------------------------------------------------
i think it will work in two section basefile and then redirect as you mentioned in your solution
also can you please reply (solution) if i want to list files/folder
with FULL PATH
without FULL PATH (just filenames)
Regards
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: how to extract single Folder / File from .tar.gz
The backup actually contains what you showed, but it contains several other tar.gz files.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: how to extract single Folder / File from .tar.gz
So for example to view the file in the inside nagios.tar.gz you could run
Code: Select all
tar -xzOf $backupfile $(basename $backupfile .tar.gz)/nagios.tar.gz | tar -ztvf -Re: how to extract single Folder / File from .tar.gz
great its working fine
hopefully now last question in this thread...sorry to bother u....but may be useful for some time some user
its showing full path, how to do some trick with awk/sed to....
list only folders with PATH
list only folders without PATH
list only files without FULL PATH
Regards
hopefully now last question in this thread...sorry to bother u....but may be useful for some time some user
its showing full path, how to do some trick with awk/sed to....
list only folders with PATH
list only folders without PATH
list only files without FULL PATH
Regards
Re: how to extract single Folder / File from .tar.gz
Here are couple examples:
list only folders with PATH (sort uniq):
list only files without FULL PATH:
Best Regards,
Vinh
list only folders with PATH (sort uniq):
Code: Select all
tar -zttf filename.tar.gz | awk '{print $6}' | sed 's/\(.*\/\)\(.*$\)/\1/g' | sort -u
Code: Select all
tar -zttf filename.tar.gz | awk '{print $6}' | sed 's/.*\///g'
Vinh