How to unzip and zip file from the Terminal?

Linux Server Management Tips and Tricks
Post Reply
arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

How to unzip and zip file from the Terminal?

Post by arnlweb » Sat Jul 22, 2017 9:21 am

How to Unzip?

# unzip file.zip -d destination_folder
# unzip filename.zip -d /home/admin/web/example.com/public_html/

How to Zip?

# zip -r filename.zip directory -x .*
# zip -r filename.zip /home/admin/web/example.com/public_html/ -x .*

arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

Re: How to unzip and zip file from the Terminal?

Post by arnlweb » Fri Jul 28, 2017 11:41 am

sudo apt-get install zip

creating a zip file:

zip -r compressed_filename.zip foldername

exclude hidden files:

find /folder_path -path '*/.*' -prune -o -type f -print | zip ~/compressed_filename.zip [email protected]

arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

Re: How to unzip and zip file from the Terminal?

Post by arnlweb » Fri Jul 28, 2017 11:42 am

zip -r zipfile.zip directory -x directory/.*

arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

Re: How to unzip and zip file from the Terminal?

Post by arnlweb » Fri Jul 28, 2017 11:45 am

TAR Example for excluding all folders beginning with:

tar cvpzf filename.tgz folder/ --exclude '.*'

Better compress (slower):

tar cvpjf filename.tar.bz2 folder/ --exclude '.*'

Post Reply