• Home
  • About

Snippet IT

IT News, Programming, Internet and Blogging

  • Programming and Scripting
  • Tips and Tricks
  • Software and Hardware
  • New and Happening
You are here: Home / Programming and Scripting / Linux: How To Compress And Decompress Folders And Files

Linux: How To Compress And Decompress Folders And Files

September 16, 2015 by Sze Hau Leave a Comment

Linux

Sometime, you may want to compress all files in a folder (or folders) in Linux into a single file to save space and so that you can back up the file to other media. In Linux, you can use the tar utilities which is installed in most Linux distribution by default.

GNU ‘tar’ saves many files together into a single tape or disk archive, and can restore individual files from the archive.

What the utility does is actually it creates an archive of the specified files and then compress the archive. Creating an archive of files is like dumping all the files content into a single file and some dictionary data (name and size of each file) so that you can extract files from the archive later on.

How to compress files and folders

To compress files and folders into a single file:

[bash title=”Syntax:”]tar -czvf output-file input-folders-or-files[/bash]

where

  • c – create a new archive
  • z – filter the archive through gzip
  • v – verbosely list files processed
  • f – use archive file
  • output-file – the output file
  • input-folders-or-file – multiple input folders or files

For example, to create a compressed archive file from the /home/user1 and /home/user2 folder:

[bash title=”Example:”]tar -czvf backup.tar.gz /home/user1 /home/user2[/bash]

It is a good practice to put the output file name with tar.gz extension so that we know that the file is created from the tar utility and it is compressed.

How to decompress and extract files and folders from a compressed tar archive

To decompress files and folders from a compressed tar archive:

[bash title=”Syntax:”]tar -xzvf input-file[/bash]

where

  • x – extract files from an archive
  • z – filter the archive through gzip
  • v – verbosely list files processed
  • f – use archive file
  • input-file – the compressed archive file

For example, to decompress and extract files from an compressed archive file:

[bash title=”Example:”]tar -xzvf backup.tar.gz /home/user1 /home/user2[/bash]

tar has many other options and uses as well. Do reading through its man page for more options.

More from my site

  • Java: Loading Large Data into JTable or JListJava: Loading Large Data into JTable or JList
  • MD5 and SHA1 Checksum Using LinuxMD5 and SHA1 Checksum Using Linux
  • Wordpress: How To Change Admin UsernameWordPress: How To Change Admin Username
  • eGenting Programming Competion 2015 And TipseGenting Programming Competion 2015 And Tips
  • Java: How To Select Top N Objects From A ListJava: How To Select Top N Objects From A List
  • eGenting Programming Competition 2013eGenting Programming Competition 2013

Filed Under: Programming and Scripting Tagged With: how to, Linux, programming

About Sze Hau

Geek. Love programming. Coffee addicted. Married with two children. Working towards financial freedom.

Leave a Reply Cancel reply

Advertisement

  • Facebook
  • Google+
  • Instagram
  • Twitter

Email News Letter

Sign up to receive updates daily and to hear what's going on with us

Software and Hardware

MD5 and SHA1 Checksum Using Windows

July 5, 2017 By Sze Hau Leave a Comment

Blog Network

  • Personal Fincance Personal Finance – Personal Money Tips, Stock Investment, Small Business and Make Money Online
  • szehau's weblog Life, Internet, Software, Gadgets, Programming and Investments

Snippet IT

This is the place where I want to share anything about information technology.

Search

Recent

  • MD5 and SHA1 Checksum Using Windows
  • MD5 and SHA1 Checksum Using Linux
  • Java: Unlimited Strength Jurisdiction Policy
  • WordPress: How To Change Admin Username
  • Linux: How To Compress And Decompress Folders And Files

Tags

Adsense advertisement advertising apache blog blogging tips C# EGPC error estimation format format Integer Gmail Google Google Adsense Google Chrome Google Search Engine Google search result how to HTTP internet marketing Java JavaScript Linux money password performance PHP programming search engine optimization secure security short URL SQL static constructor String tiny URL Tips and Tricks twitter video Windows Vista Wordpress wordpress plugin wordpress theme Youtube

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in