Linux commands to compress and decompress files and directories

Being an avid linux os user, I often find myself googling how to compress a single file or a directory using bash terminal. The purpose of this article is to compile all those handy commands that I have to copy-paste from internet.

Zip files …


This content originally appeared on DEV Community and was authored by Abdullah Al Nahid

Being an avid linux os user, I often find myself googling how to compress a single file or a directory using bash terminal. The purpose of this article is to compile all those handy commands that I have to copy-paste from internet.

Zip files or folders

###### For a single file
zip <output-zip-file> <input-filename>

###### For multiple files
zip <output-zip-file> <file-1> <file-2> ... <file-n>

###### For multiple files with same extension (.csv, .pdf) 
zip <output-zip-file> *<extension>

###### For a folder
zip -r <output-zip-file> <input-folder-name>

###### For multiple folders
zip -r <output-zip-file> <folder-1> <folder-2> ... <folder-n>

For example:

###### For myfile.txt file
zip document.zip myfile.txt

###### For multiple files
zip files.zip report.docx document.pdf data.txt

###### For multiple files with same extension (.csv, .pdf)
zip pdfs.zip *.pdf
zip textfiles.zip *.txt

###### For Documents folder
zip -r temp.zip Documents

###### For Books and Documents folders
zip -r folders.zip Books Documents

Unzip a zipped file

unzip <zip-filename>

For example:

unzip document.zip

In case of error unzip command not found, run this:

sudo apt-get install unzip

tar.gz files or folders

###### For a file
tar -czvf <output-file> <input-file>

###### For a folder
tar -czvf <output-file> <input-folder>

For example:

###### For myfile.csv file
tar -czvf file.tar.gz myfile.csv

###### For Work folder
tar -czvf work.tar.gz Work

Uncompress tar.gz files or folders

tar -xvf <tar-gz-file>

For example:

tar -xvf work.tar.gz


This content originally appeared on DEV Community and was authored by Abdullah Al Nahid


Print Share Comment Cite Upload Translate Updates
APA

Abdullah Al Nahid | Sciencx (2021-09-14T09:25:12+00:00) Linux commands to compress and decompress files and directories. Retrieved from https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/

MLA
" » Linux commands to compress and decompress files and directories." Abdullah Al Nahid | Sciencx - Tuesday September 14, 2021, https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/
HARVARD
Abdullah Al Nahid | Sciencx Tuesday September 14, 2021 » Linux commands to compress and decompress files and directories., viewed ,<https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/>
VANCOUVER
Abdullah Al Nahid | Sciencx - » Linux commands to compress and decompress files and directories. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/
CHICAGO
" » Linux commands to compress and decompress files and directories." Abdullah Al Nahid | Sciencx - Accessed . https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/
IEEE
" » Linux commands to compress and decompress files and directories." Abdullah Al Nahid | Sciencx [Online]. Available: https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/. [Accessed: ]
rf:citation
» Linux commands to compress and decompress files and directories | Abdullah Al Nahid | Sciencx | https://www.scien.cx/2021/09/14/linux-commands-to-compress-and-decompress-files-and-directories/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.