While working with the archive files, sometimes you are required to list archive file contents instead of extract an archive file. Using this you can see the files available in an archive file. Read another tutorial with 18 Linux tar command examples

Advertisement

List Archive File Contents (Quick Commands)

The -t switch is used for list content of a tarball file without extract. Below is the quick commands used to list .tar, .tar.gz, .tar.bz2 and .tar.xz file contents.

tar -tvf archive.tar
tar -ztvf archive.tar.gz
tar -jtvf archive.tar.bz2
tar -Jtvf archive.tar.xz

List .tar File Content

Use -t switch with tar command to list content of a archive.tar file without actually extracting. You can see that output is pretty similar to the result of ls -l command.

tar -tvf archive.tar

[Sample Output]

drwxr-xr-x root/root         0 2018-01-12 11:11 backup/
drwxr-xr-x root/root         0 2018-01-12 11:09 backup/data/
-rw-r----- root/root      1058 2018-01-12 11:09 backup/data/config.ini
-rw-r--r-- root/root        29 2018-01-12 11:11 backup/.htaccess
-rw-r----- root/root       442 2018-01-12 11:08 backup/access.log
-rw-r--r-- root/root         7 2018-01-12 11:09 backup/index.html
lrwxrwxrwx root/root         0 2018-01-12 11:11 backup/config -> data/config.ini

List .tar.gz File Content

We use -z switch for handling .tar.gz files and use -t for the listing of archive file content. See below example to list an archive.tar.gz file contents without extracting the file.

tar -ztvf archive.tar.gz

[Sample Output]

drwxr-xr-x root/root         0 2018-01-12 11:11 html/
drwxr-xr-x root/root         0 2018-01-12 11:09 html/config/
-rw-r----- root/root      1058 2018-01-12 11:09 html/config/config.ini
-rw-r--r-- root/root        29 2018-01-12 11:11 html/.htaccess
-rw-r----- root/root    442488 2018-01-12 11:08 html/access.log
-rw-r----- root/root    263636 2018-01-12 11:08 html/error.log
-rw-r--r-- root/root        17 2018-01-12 11:09 html/index.html
lrwxrwxrwx root/root         0 2018-01-12 11:11 html/config.ini -> config/config.ini

List .tar.bz2 File Content

We use -j switch for handling tar.bz2 files and use -t for the listing of archive file content. See below example to list an archive.tar.bz2 file contents without extracting the file.

tar -jtvf archive.tar.bz2

[Sample Output]

drwxr-xr-x root/root         0 2018-01-12 11:11 www/
drwxr-xr-x root/root         0 2018-01-12 11:09 www/data/
-rw-r----- root/root      1994 2018-01-10 10:19 www/data/config.ini
-rw-r--r-- root/root        29 2018-01-12 11:11 www/.htaccess
-rw-r----- root/root     33442 2018-01-11 10:08 www/index.php
lrwxrwxrwx root/root         0 2018-01-12 11:11 www/config -> data/config.ini

List .tar.xz File Content

We use -J (capital J) switch for handling tar.xz files and use -t for the listing of archive file content. See below example to list an archive.tar.xz file contents without extracting the file.

tar -Jtvf archive.tar.xz

[Sample Output]

drwxr-xr-x root/root         0 2018-01-12 11:11 www/
drwxr-xr-x root/root         0 2018-01-12 11:09 www/data/
-rw-r----- root/root      1994 2018-01-10 10:19 www/data/config.ini
-rw-r--r-- root/root        29 2018-01-12 11:11 www/.htaccess
-rw-r----- root/root     33442 2018-01-11 10:08 www/index.php
lrwxrwxrwx root/root         0 2018-01-12 11:11 www/config -> data/config.ini
Share.

1 Comment

Exit mobile version