How to Compress and Uncompress Files with SSH

Login to SSH:

1) To compress files:
Examples:

tar cvf abc.tar a1.ps a2.tex adir/* # compress files to the file abc.tar
gzip -9 abc.tar /* # create abc.tar.gz file.
tar cvfz abc.tar.gz a1.ps a2.tex adir/* # directly create abc.tar.gz file
zip abc.zip a1.ps a2.tex adir/* # directly create abc.zip file

Note that -9 means the slowest compression method (best compression). By default, -6 is used. -1 means fastest compression method (less compression). The command zip is compatible with PKUNZIP on pc. Thus, the file abc.zip can be uncompressed by WinZip.

2) To uncompress files:
Examples:

tar xvf abc.tar # uncompress abc.tar file
gunzip abc.tar.gz # after uncompress, get abc.tar
tar xvfz abc.tar.gz #unzip and utar *.tar.gz file
unzip abc.zip #unzip .zip file

To view the content of the compressed file:
Examples:

tar tvf abc.tar
tar tvfz abc.tar.gz
unzip -l abc.zip

  • 43 Users Found This Useful
Was this answer helpful?

Related Articles

Setup & disable unused services on CentOS

Step 1: Now we will remove all software groups, to get Centos to a minimum Step 1.1: Run...

install g++ on CentOS

g++ is often necessary for building various packages. But It’s quite hard to install it in...

Repair all tables on server with SSH

Login to SSH. Try to run this command: mysqlcheck -A -h localhost -u root -r -p It asks mysql...

scp resume after got disconnected or timeout

I often use the UNIX command line tool scp (secure copy) to copy a file to a remote server....

Search file theo dung lượng

Use this: find / -size +10000 Dùng lệnh trên để tìm các file có dung lượng >= 10MB