User Tools

Site Tools


unix_commands:tar

The tar command in Linux and Unix-like systems is used to create, extract, and manipulate archive files. A tar archive is a single file that contains multiple files and directories, similar to a zip archive. The tar file format is commonly used for software distribution and backups.

Here are a few examples of how the tar command can be used:

  1. Create a tar archive: tar -cvf archive.tar file1 file2 file3
  2. Extract a tar archive: tar -xf archive.tar
  3. Extract a specific file or directory: tar -xf archive.tar file1
  4. Create a compressed (gzip) tar archive: tar -zcvf archive.tar.gz file1 file2 file3
  5. Extract a compressed (gzip) tar archive: tar -zxvf archive.tar.gz
  6. Create a compressed (bzip2) tar archive: tar -jcvf archive.tar.bz2 file1 file2 file3
  7. Extract a compressed (bzip2) tar archive: tar -jxvf archive.tar.bz2
  • The -c option is used to create an archive
  • The -x option is used to extract an archive
  • The -v option is used to display verbose output/
  • The -f option is used to specify the archive file name
  • The -z option is used to create or extract a gzip compressed archive
  • The -j option is used to create or extract a bzip2 compressed archive,
  • The -p option is used to preserve the file permissions and ownership when creating an archive,
  • The -C option is used to extract the archive to a specific directory.

It's also possible to use tar command to add files to an existing archive by using the -r option, for example:

tar -rvf archive.tar file4

This command will add file4 to the archive.tar

You can also use –exclude option to exclude certain files or directories while creating an archive, for example:

tar -cvf archive.tar --exclude='*.log' /var/log

This command will create an archive of all files and directories in /var/log except for files with .log extension.

unix_commands/tar.txt · Last modified: 2023/01/18 11:00 by admin

CIFNet is a leading hosting solution provider, offering a wide range of services including IP bandwidth, co-location, VMware and KVM hosting.
Host Your Site with CIFNet!