Looking for CLI commands to create tar and zip archives so that you can transfer a couple of files and folders to a different machine with ease? The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to another disk or machine to machine. The same purpose is served by zip. Zip also creates a compressed archive file.

 

Create tar archive

 

We will create a tarball for a folder named ‘data’.

Command – 
tar -cvf backup.tar data/

 

c – Creates a new .tar archive file.

v – Verbosely show the .tar file progress.

f– File name type of the archive file.

 

Extract tar archive

 

We will extract a backup.tar archive

 

Command – 
tar -xvf backup.tar

 

x – Extracts tar archive file.

v – Verbosely show the .tar file progress.

f – File name type of the archive file.

 

Create zip archive

 

We will create a zip archive for a folder named ‘data’.

 

Command – 
zip -r4 backup.zip data/

 

r – the recursive flag to include all files and subfolders

4 – Level of compression to use for the zip archive

 

Extract zip archive

 

We will extract a zip archive named backup.zip

 

Command – 
unzip backup.zip

 

這篇文章有幫助嗎? 0 用戶發現這個有用 (0 投票)