Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»How to List Archive File Contents in TAR/TAR.GZ/TAR.BZ2

    How to List Archive File Contents in TAR/TAR.GZ/TAR.BZ2

    RahulBy RahulJanuary 7, 20183 Mins ReadUpdated:February 21, 2018

    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

    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
    
    tar
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Get Current Date & Time in PHP
    Next Article How to Install Eclipse 4.8 on Ubuntu 18.04 & 16.04 LTS

    Related Posts

    Running Multiple Commands At Once in Linux

    Updated:August 6, 20223 Mins Read

    Convert String to Lowercase in Bash – Easier Than You Think

    Updated:August 1, 20221 Min Read

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    tee Command in Linux with Examples

    Updated:July 1, 20224 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    1 Comment

    1. Sanjay Mishra on January 13, 2018 4:03 am

      Thanks… It’s helped me a lot …

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.