Solved

Need gzip examples in pipe

Posted on 2004-09-09
8
6,027 Views
Last Modified: 2008-03-10
For a learning purposes I search a simple examples for using gzip in pipe
with basic linux commands
Something like
......   | gzip -c > .....
or
......   | gzip -d > .....


(not only tar nor , I need a factics output for any simple Linux commands )
Can anybody help me quick ???

Thanks
Petr

0
Comment
Question by:hatina
8 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12014726
Hi hatina,

check gzip man page for more examples
cat file1 file2 | gzip > foo.gz
gzip -cd old.gz | gzip > new.gz

Sunnycoder
0
 

Author Comment

by:hatina
ID: 12014966
I do not need simple gzip using,...
I need a practical examples cooperative with another Linux commands through pipe.........!!!!!!!!!!!!
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12014994
Which commands ?? The above are as good as practical exmaples ... you can complicate either side of pipe as much as you desire

cat file1 file2 | gzip > foo.gz

can be morphed to

find <some_dir> -type f -name "foo" -exec car {} \; | gzip > total_foo.gz
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 12014998
find <some_dir> -type f -name "foo" -exec cat {} \; | gzip > total_foo.gz
                                                                 ^
0
 

Expert Comment

by:cuspoon
ID: 12018997
There is always the simple

gzip -c (file.tgz) | tar xvf -
0
 

Expert Comment

by:cuspoon
ID: 12019041
I hate it when fingers slip off the keys...   There is a missing key in there.

gzip -cd (file.tgz) | tar x

or for those of us who like output

gzip -cd (file.tgz) | tar xv

or still

gzip -cd (file.tgz) | tar xvf -
0
 
LVL 3

Accepted Solution

by:
255x4 earned 125 total points
ID: 12028477
The pipe ( | ) command is simply a way of redirecting stdout information, and sending it to another command as if it was text being entered to it.  For gzip, this would be in place of telling gzip to compress a particular file, but rather compress the stdout data until it reaches an EOF (End Of File) statement.

Note, the pipe does not allow program interaction, it does not output the stderr signal, just stdout.  There is no way for the next program to know if something went wrong.  Nor can later programs communicate with previous programs.  This is a one way, stream only, signal.

If you wish to take stdout data, pipe it to gzip, then have that go to the stdout and possibly be piped somewhere else, then here ya go:

{command} | gzip -f | {other command}

example:

cat examplefile.txt | gzip -f |

I really can't think of anything to do with this binary stream after gzip'ing it, but if you want to, do what you will.

Thanks,
255x4
0
 
LVL 2

Expert Comment

by:Sunjith
ID: 12039447
Another practical example ;-)
Say, you have to capture all packets going through your network interface for some time and you may want to store it in an archive. You may then use a command like follows:
tcpdump -s0 -X -vv | gzip > dump.gz
(You have to kill tcpdump from another terminal. If you press Ctrl+C in the same terminal, gzip cannot close the archive properly.)
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Difficulties extending an XFS root partition on CentOS 7 on a Virtual Machine (Hyper V on Windows Server 2012) 9 122
linux 13 77
The better OS Architecture 13 69
Apache module 5 48
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question