Solved

Need gzip examples in pipe

Posted on 2004-09-09
8
6,005 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
find <some_dir> -type f -name "foo" -exec cat {} \; | gzip > total_foo.gz
                                                                 ^
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:cuspoon
Comment Utility
There is always the simple

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

Expert Comment

by:cuspoon
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now