Can you use gzip to just compress text that you type into the terminal?
If yes, then how?
If no, then what does this line mean?:
When you do not specify any files to be compressed or specify – as a file name, gzip reads from the standard input, compresses what is read, and writes the result out to the standard output.
I’ve read it on many web pages, including this one: http://www.mkssoftware.com/docs/man1/gzip.1.asp
Also, when I type gzip -f in my terminal, cursor goes to newline and starts accepting input but I just have to Ctrl+C it out and then nothing happens.
Yes, you can, but it’s not a common thing to do.
For example, this is perfectly legal (I typed “
Hello, world.“, then Enter, then Ctrl-D).(The compressed file is actually bigger than the input; this is common for very small inputs.)
But remember that standard input doesn’t have to come from the keyboard. For example, the
ducommand prints a summary of disk usage, and can generate a lot of output if you run it on a large directory. If you want to save the output directly in compressed form, you might type:The standard input of the
gzipcommand comes from the output of thedu -a /command; its standard output is written to the new filedu-a.out.gz.The
tarcommand is another common example:(but many versions of
tarhave options to do this without having to explicitly invoke thegzipcommand).As for the last part of your question:
Typing Ctrl-C kills the
gzipprocess, and may not allow it to finish writing its output. You need to type Ctrl-D to trigger an end-of-file condition; this lets thegzip -fcommand finish normally. But you don’t generally want to do that; it will write the compressed output to your terminal, which can include control characters that can mess up your terminal settings.