Thursday, 30 November 2023   |

How to Create and Extract Tar Archive Files in Linux


Creating and extracting tar archive files in Linux is a common task performed through the command line. The "tar" command is used for these operations. Here's how you can create and extract tar archives in Linux:

Creating a Tar Archive:
To create a tar archive, you can use the following command:

```shell
tar -cvf archive.tar files...
```

In this command:
- The `-c` option specifies that you want to create a new archive.
- The `-v` option (optional) enables verbose output, displaying the list of files being included in the archive.
- The `-f` option is used to specify the name of the archive file you want to create.
- `files...` represents one or more files or directories you want to include in the archive.

For example, to create an archive called "myfiles.tar" containing three files (file1.txt, file2.txt, and directory/), you can use the following command:

```shell
tar -cvf myfiles.tar file1.txt file2.txt directory/
```

Extracting a Tar Archive:
To extract the contents of a tar archive, you can use the following command:

```shell
tar -xvf archive.tar
```

In this command:
- The `-x` option specifies that you want to extract the archive.
- The `-v` option (optional) enables verbose output, displaying the list of files being extracted.
- The `-f` option is used to specify the name of the archive file you want to extract.

For example, to extract the contents of the "myfiles.tar" archive, you can use the following command:

```shell
tar -xvf myfiles.tar
```

This command will extract the files and directories stored in the archive to the current directory.

You can explore additional options and functionalities of the `tar` command by referring to its manual page using the following command:

```shell
man tar
```

That's it! You now know how to create and extract tar archives in Linux using the command line.


Date: 20 June 2023    Comments: 0


Comments - 0

There are no comments yet

Leave A Comment