😎
CS1.dev
  • Welcome to Computer Science 1
  • Unit 2
    • Activity 2.1
    • Activity 2.2
    • Activity 2.3
    • Activity 2.4
    • Activity 2.5
    • Activity 2.6
    • Activity 2.7
    • Activity 2.9
    • Activity 2.10
    • Project 2
    • Activity 2.8
    • Activity 2.11
    • Activity 2.12
    • Activity 2.13
    • Activity 2.14
    • Activity 2.15
    • Activity 2.16
    • Activity 2.17
    • Activity 2.18
    • Activity 2.19
    • Project 3
    • Activity 2.20
    • Activity 2.21
    • Activity 2.22
    • Activity 2.23
    • Activity 2.24
    • Project 4
    • Activity 2.25
    • Activity 2.26
    • Activity 2.27
    • Activity 2.28
    • Project 5
    • Activity 2.29
    • Activity 2.30
    • Activity 2.31
    • Activity 2.32
    • Activity 2.33
    • Activity 2.34
    • Activity 2.35
    • Activity 2.36
  • Unit 3
    • Activity 3.1
    • Activity 3.2
    • Activity 3.3
    • Activity 3.4
    • Activity 3.5
    • Activity 3.6
    • Activity 3.7
    • Activity 3.8
    • Activity 3.9
    • Activity 3.10
    • Activity 3.11
    • Project 6
    • Activity 3.12
  • Activity 3.13
  • Activity 3.14
  • Activity 3.15
  • Activity 3.16
  • Project 7
  • Activity 3.17
  • Activity 3.18
  • Activity 3.19
  • Project 8
  • Linux
    • bash
    • cat
    • cd
    • chmod
    • df
    • echo
    • find
    • grep
    • less
    • ls
    • mkdir
    • more
    • pwd
    • tar
    • touch
    • unzip
    • zip
Powered by GitBook
On this page
  1. Linux

tar

The tar command in Linux is a highly versatile tool used for file archiving and compression. The name tar stands for "Tape Archive", a throwback to its original purpose for writing data to tape drives. It allows multiple files and directories to be bundled together into a single archive file (commonly known as a tarball), and optionally compress it for space efficiency. Here are the key aspects and functionalities of the tar command:

  1. Creating Archives: To create a tarball, tar is used with the -c (create) option, along with -f to specify the filename of the archive. For example, tar -cf archive.tar file1 file2 dir1 will create an archive file named archive.tar containing file1, file2, and dir1.

  2. Viewing Archive Contents: To view the contents of a tarball without extracting it, use the -t (list) option. For example, tar -tf archive.tar lists the contents of archive.tar.

  3. Extracting Archives: To extract the contents of a tarball, use the -x (extract) option. For example, tar -xf archive.tar will extract the contents of archive.tar into the current working directory.

  4. Compression: tar can be combined with compression methods like gzip or bzip2. To create a compressed tarball, you use additional options: -z for gzip (resulting in .tar.gz or .tgz files) or -j for bzip2 (resulting in .tar.bz2 files). For example, tar -czf archive.tar.gz directory will create a gzipped tarball of directory.

  5. Decompressing and Extracting: To extract a compressed tarball, you include the same compression option. For example, tar -xzf archive.tar.gz will extract the contents of a gzipped tar archive.

  6. Appending Files to an Archive: The -r option allows you to append files to an existing tarball. Note that this doesn’t work with compressed archives.

  7. Updating an Archive: The -u option is used to update files within an archive that have changed since the archive was created.

  8. Preserving Permissions: tar preserves file permissions and ownership in the archive, which makes it a popular choice for backups and transferring files between systems.

  9. Piping and Redirection: tar can be used with piping and redirection in Linux. For example, you can pipe the output of tar to ssh for remote backups or use it with other commands for advanced file processing tasks.

PreviouspwdNexttouch

Last updated 1 year ago