How To Archive Files and Directories in Linux

Introduction

Archiving is the process of combining multiple files and directories (same or different sizes) into one file. On the other hand, compression is the process of reducing the size of a file or directory. Archiving is usually used as part of a system backup or when moving data from one system to another.

Archives and Directories

The most common programs for archiving files and directories are:

  • Tar
  • Zip

Archive files and directories using the tar command

Tar is a Unix command representative TAPE Archive (tape archive). It is used to combine or store multiple files (same or different into one file. There are four main modes of operation in the tar utility.

  • c – Create an archive from a file or directory
  • x – Extract archive
  • r – Append file to archive
  • t – List the contents of the archive

Create a new archive

  • Common tar archives: tar -cf archive.tar file1 file2 file3
  • Gzip tar archive: tar -czf archive.tgz file1 file2 file3
  • Bzip tar archive: tar -cjf archive.tbz file1 file2 file3
SYNTAX 1

Extract tar archives:

  • Common tar archives: tar -xf archive.tar
  • Gzip tar archive: tar -xzf archive.tgz
  • Bzip tar archive: tar -xjf archive.tbz
SYNTAX 2

Leave a Comment

Your email address will not be published. Required fields are marked *