Thursday, May 2, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3286  / 2 Years ago, thu, april 28, 2022, 5:01:41

can someone tell me if is possible to directly compress stdout?



I would like to do this in one step without creating temporary file files.txt...



Example:



cat file* > files.txt
tar -czf files.tar files.txt
rm files.txt


Is this possible?


More From » command-line

 Answers
6

You can bypass the tar part of .tar.gz in this case, since you don't need to handle multiple files, and skip straight to gzip for compression.



To compress



gzip < file > file.gz


To decompress



gzip -d file.gz


or equivalently



gunzip file.gz


You can also use the bzip2 and xz compression utilities with similar syntax. xz usually produces smaller compressed files than either gzip or bzip2.



(Footnote)



If you are creating a compressed file and then using scp to transfer it, you can use built-in compression:



cat file | ssh -C user@remote 'cat >> remote_file'


or



scp -C file user@remote:/path/on/remote


or



rsync -avz file user@remote:/path/on/remote    

[#34394] Thursday, April 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nuehan

Total Points: 253
Total Questions: 109
Total Answers: 120

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;