---
title: "tar Command &#8211; Basic Archiving"
description: "Learn how to create, extract, and list files within a compressed tar archive in Secure Shell (SSH), or cPanel Terminal, with the tar command. Create an archiveExtract FilesList Archived Files Want to..."
url: https://www.inmotionhosting.com/support/website/tar-command-basic-archiving/
date: 2019-10-29
modified: 2021-08-16
author: "InMotion Hosting Contributor"
categories: ["Linux", "Website"]
type: post
lang: en
---

# tar Command &#8211; Basic Archiving

Learn how to create, extract, and list files within a compressed tar archive in [Secure Shell (SSH)](/support/server/ssh/do-you-provide-ssh-access/), or cPanel Terminal, with the `tar` command.

- [Create an archive](#create)
- [Extract Files](#extract)
- [List Archived Files](#list)

Want to spend more time working on your website than setup? Check out our Shared Business Hosting with Softaculous Instant Installer and WP-CLI included.

## Create an Archive

```
tar -czvf archive-name.tar.gz path-to-directory-or-files
```

Example: `tar -czvf images.tar.gz *.png` – Archive all PNG image files in the current directory into a images.tar.gz file
Example: `tar -czvf backup.tar.gz *` – Archive all files and folders in the current directory into a backup.tar.gz file

`-c` – create
`-z` – compress or decompress
`-v` – list files processed
`-f` – specify filename

## Extract Files

```
tar -xzvf archive.tar.gz
```

Example: `tar -xzvf images.tar.gz`

Used options:

`-x` – Extract
`-z` – compress or decompress
`-v` – list files processed
`-f` – specify filename

### Extract to Another Directory

```
tar -xzvf archive.tar.gz -C another-folder
```

Example: `tar -xzvf images.tar.gz -C *restored*` – Extract files from the images.tar.gz file into an existing /restored folder

Used options:

`-x` – Extract
`-z` – compress or decompress
`-v` – list files processed
`-f` – specify filename
`-C` – Specify directory

## List Files

```
tar -tvf archive.tar.gz
```

Used options:

`-t` – list files processed
`-v` – list files processed (with more info including file size and date modified)
`-f` – specify filename

For more options, type the `tar --help` command or visit [GNU.org](https://www.gnu.org/software/tar/manual/tar.html).
