Copied to clipboard

tar

The tar command is a command-line tool used to pack and compress files in Linux and Unix operating systems. Its name is an abbreviation of "tape archive" because it was originally used to create backups on tape.

Create a new archive file

Directory path

Add files to the archive file

Directory path

Only add newer files to the archive file

Directory path

Display the contents of the archive file

Extract files and directories from the archive file

Directory path

Compare differences between archive file and file system

Directory path

Example

  • tar -cvf file.tar /path/to/folder, pack the /path/to/folder directory into a file.tar file.
  • tar -xvf file.tar, extract the archive file named file.tar.
  • tar -zcvf file.tar.gz /path/to/folder, pack the /path/to/folder directory and compress it to a file.tar.gz file using gzip.
  • tar -jcvf file.tar.bz2 /path/to/folder, pack the /path/to/folder directory and compress it to a file.tar.bz2 file using bzip2.
  • tar -tvf file.tar, view the list of files contained in the file.tar file.
  • tar -rvf file.tar /path/to/newfile, add the /path/to/newfile file to the archive file named file.tar.
  • tar -f archive.tar --delete file1.txt file2.txt, delete the "file1.txt" and "file2.txt" files from the archive file named "archive.tar". Note that the --delete parameter can only be used for .tar format archive files, and not for compressed format archive files such as .tar.gz, .tar.bz2, etc. In addition, the --delete parameter may not be supported in some tar implementations, so please check whether it is available based on the version of tar and the operating system you are using.