There are some cases when you want to create compressed tar archive but you do not have enough disk space to keep original files and tar archive or you would like to speedup the process or you do not have GNU tar (which support x,z flags for compress the tar). In such case you can use one small trick which will save you some disk space and on the same time will speedup the process because or parallel run of the commands.
Instead of run:
tar czf file.tar.gz files_to_be_archived
you can run it on this way:
tar cf - files_to_be_archived|gzip -c >file.tar.gz
This will avoid creation of temporary intermediate file and run tar and gzip in parallel. Usage of dash (-) is good practice because in UNIX OS absence of name of file archive will send the output of command to real tape device.
You can find the original discussion in Unix StackExchange
Showing posts with label compress. Show all posts
Showing posts with label compress. Show all posts
Play with compressed tar files
Time to time every system administrator or user should extract file or entire archive from compressed tar, but quite often in filesystems there is not enough free space. In this case it's possible to extract file(s) on the fly without first uncompress and then untar:
gzip -dc archive.tar.gz|tar xf -
The above line can be modified when you should deal with broken archives. If you try to decompress such archive gzip just stop when find error in compression. But you want to save what's possible. So let's make it on this way:
cat archive.tar.gz|gzip -dc|tar xf -
I know it is possible to use GNU tar to extract files from compressed archive, but in UNIX world you can't be sure this software is installed :-)
Few remarks:
gzip -dc archive.tar.gz|tar xf -
The above line can be modified when you should deal with broken archives. If you try to decompress such archive gzip just stop when find error in compression. But you want to save what's possible. So let's make it on this way:
cat archive.tar.gz|gzip -dc|tar xf -
I know it is possible to use GNU tar to extract files from compressed archive, but in UNIX world you can't be sure this software is installed :-)
Few remarks:
- It's wise to use 'f -' key because in some Unixes without explicit 'f' tar will use tape device or whatever is defiined in TAPE variable
- In above examples beside less diskpace usage you benefit from parallel execution (from pipe)
Subscribe to:
Posts (Atom)
Should I trust AI
Should I trust AI? So far no, sorry. I tested for the moment (May, 2025) most advanced model for programming and ask very simple question:...
-
Grow soft partition on the fly 1. Create random file and calculate checksum # cd /oradata # dd if=/dev/urandom of=file bs=1024 count=10...
-
To build firewall under AIX is sample, but as each host based firewall should be done careful 1. Prerequisites To start firewall in AIX yo...
-
There are some cases when you want to create compressed tar archive but you do not have enough disk space to keep original files and tar arc...