Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Commands»How to Extract a Tar.bz2 File

    How to Extract a Tar.bz2 File

    By RahulFebruary 1, 20233 Mins Read

    A “tar.bz2” file is a compressed archive file created using the tar command in Unix/Linux and the bzip2 compression algorithm. It is commonly used for distributing large files or groups of files as a single archive, which is smaller in size compared to the original files, making it easier to transfer and manage.

    Advertisement

    The tar command is used to create an archive of multiple files or directories and the bzip2 compression algorithm is used to reduce the size of the archive. The resulting archive file has a .tar.bz2 extension and can be unpacked using the tar command with the -j option.

    We can unzip a .tar.bz2 file using Linux tar command. In this tutorial, you will learn the followings:

    • How to Unzip tar.bz2 file
    • How to Create tar.bz2 compressed file
    • Command to list the content of tar.bz2 without extracting it

    How to Unzip tar.bz2 file

    You can use Linux tar command with option -j to extract bz2 file. As this is a also tar compressed file, You also need to use -x command line option.

    So we can use -xjf options with the tar command to extract a .tar.bz2 file:

    tar -xjf filename.tar.bz2
    

    The above command will extract tar.bz2 file content in current directory.

    To extract files in a defend location, use -C option followed by the destination directory.

    tar -xvjf filename.tar.bz2 -C /opt 
    

    Now all the files will be extracted under /opt directory.

    How to create tar.bz2 file

    The tar command uses -c to create a compressed tar archive file. You can also use -j to create a tar.bz2 archive file.

    For example, to create a backup of your web server directory, execute:

    tar -cjf backup.tar.bz2 /var/www/html 
    

    The above command will compress all the files available under /var/www/html directory and create backup.tar.bz2 compressed file in current directory.

    How to list tar.bz2 content without extract

    You never need to extract a archive file to just view the file content. Use -t with -v (verbose) command line option to list archive file content only.

    tar -tvjf backup.tar.bz2
    
    Output
    drwxr-xr-x root/root 0 2023-02-01 11:54 var/www/html/ drwxr-xr-x root/root 0 2023-02-01 11:54 var/www/html/static/ drwxr-xr-x root/root 0 2023-02-01 11:55 var/www/html/static/js/ -rw-r--r-- root/root 14150 2023-02-01 11:55 var/www/html/static/js/main.js drwxr-xr-x root/root 0 2023-02-01 11:55 var/www/html/static/css/ -rw-r--r-- root/root 14149 2023-02-01 11:55 var/www/html/static/css/main.css -rw-r--r-- root/root 10701 2023-01-31 11:01 var/www/html/index.html

    Conclusion

    An archive file are useful for creating backups, making bundle of files and save disk space. In this tutorial, you have learned how to extract a .tar.bz2 file using command line. Additionally, you learned to create .tar.bz2 file or list files without extracting it.

    archive bzip extract tar
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    cp Command in Linux (Copy Files Like a Pro)

    dd Command in Linux (Syntax, Options and Use Cases)

    Top 10 JQ Commands Every Linux Developer Should Know

    View 1 Comment

    1 Comment

    1. Thiyagu Ganesan on May 21, 2017 5:25 am

      Thanks for sharing the good details. If you still get an error, even after trying out the above steps – please do the below.

      #yum install bzip2 -y

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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