tar – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Fri, 26 Feb 2021 06:44:55 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to List Archive File Contents in TAR/TAR.GZ/TAR.BZ2 https://tecadmin.net/list-archive-file-contents-tar/ https://tecadmin.net/list-archive-file-contents-tar/#comments Sun, 07 Jan 2018 17:45:05 +0000 https://tecadmin.net/?p=14683 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 [...]

The post How to List Archive File Contents in TAR/TAR.GZ/TAR.BZ2 appeared first on TecAdmin.

]]>
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

The post How to List Archive File Contents in TAR/TAR.GZ/TAR.BZ2 appeared first on TecAdmin.

]]>
https://tecadmin.net/list-archive-file-contents-tar/feed/ 1
How to Create tar Archive excluding some Files & Directories https://tecadmin.net/create-tar-archive-excluding-some-files-directories/ https://tecadmin.net/create-tar-archive-excluding-some-files-directories/#comments Mon, 19 Jan 2015 08:52:45 +0000 https://tecadmin.net/?p=6525 Tar Command: tar czf backup.tar.gz --exclude "wp-content/cache" public_html Above command will archive all files and directories under public_html directory except wp-content/cache directory and create a archive file named backup.tar.gz. Examples Exclude a single directory inside other directory. Create archive of all files under public_html directory ignoring all files and folders including text backup in there [...]

The post How to Create tar Archive excluding some Files & Directories appeared first on TecAdmin.

]]>

Tar Command:

tar czf backup.tar.gz --exclude "wp-content/cache" public_html

Above command will archive all files and directories under public_html directory except wp-content/cache directory and create a archive file named backup.tar.gz.

Examples

  • Exclude a single directory inside other directory. Create archive of all files under public_html directory ignoring all files and folders including text backup in there named
    tar czf backup.tar.gz --exclude "wp-content/uploads" public_html
    
  • You can define multiple exclude in single command. For example create and archive of all files under public_html directory ignoring .svn or .git files and directories.
    tar czf backup.tar.gz --exclude ".svn" --exclude ".git" public_html
    
  • To exclude a specific file define full path of the file. For example exclude “logs/access.log” inside public_html directory.
    tar czf backup.tar.gz --exclude "logs/access.log" public_html
    
  • Create archive of all files under public_html directory ignoring all files and directories starting with dot ( . ) (hidden files).
    tar czf backup.tar.gz --exclude "*.log" public_html
    

The post How to Create tar Archive excluding some Files & Directories appeared first on TecAdmin.

]]>
https://tecadmin.net/create-tar-archive-excluding-some-files-directories/feed/ 2
How to Extract (Unzip) tar.bz2 File https://tecadmin.net/how-to-extract-tar-bz2-file/ https://tecadmin.net/how-to-extract-tar-bz2-file/#comments Tue, 25 Nov 2014 12:51:50 +0000 https://tecadmin.net/?p=6488 A tar.bz2 file is compressed file using Tar with a Burrows-Wheeler (BZ2) compression algorithm. These file will have the extension “.tar.bz2“. Most commonly, this file format is used for distributing software packages on Unix based operating systems. We can unzip a .tar.bz2 file using Linux tar command. In this tutorial, you will learn the followings: [...]

The post How to Extract (Unzip) tar.bz2 File appeared first on TecAdmin.

]]>
A tar.bz2 file is compressed file using Tar with a Burrows-Wheeler (BZ2) compression algorithm. These file will have the extension “.tar.bz2“. Most commonly, this file format is used for distributing software packages on Unix based operating systems.

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 files
  • Command to list tar.bz2 content without extract

How to Unzip tar.bz2 file

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

So use -xv with tar command to extract a .tar.bz2 file:

tar -xvjf filename.tar.bz2

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

To extract files in other directory, use -C option with destination directory.

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

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.

tar -cjf filename.tar.bz2 *.log 

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 -tvzf filename.tar.bz2


-rw------- root/root    863287 2014-08-14 17:35:58 anaconda.log
-rw------- root/root         0 2014-12-29 02:17:27 boot.log
-rw-r--r-- root/root         0 2014-12-29 02:17:26 kdm.log
-rw-r--r-- root/root     25643 2014-12-29 01:12:35 Xorg.0.log
-rw-r--r-- root/root     11380 2014-11-24 17:35:39 yum.log

Conclusion

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 extract.

The post How to Extract (Unzip) tar.bz2 File appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-extract-tar-bz2-file/feed/ 1
3 Most Popular Tools to Archive Files and Directories in Linux https://tecadmin.net/popular-tools-to-archive-files-and-directories-in-linux/ https://tecadmin.net/popular-tools-to-archive-files-and-directories-in-linux/#respond Sat, 22 Nov 2014 09:11:05 +0000 https://tecadmin.net/?p=6326 There are multiple tools available in Linux system for creating archive files. In this article you will find uses of multiple tools for creating or extracting archive files through command line Tool 1 – Zip zip is the most popular command line archiving utility for Linux systems. Create Archive of File # zip output.zip /var/log/*.log [...]

The post 3 Most Popular Tools to Archive Files and Directories in Linux appeared first on TecAdmin.

]]>
There are multiple tools available in Linux system for creating archive files. In this article you will find uses of multiple tools for creating or extracting archive files through command line


Tool 1 – Zip

zip is the most popular command line archiving utility for Linux systems.

Create Archive of File

# zip output.zip /var/log/*.log

Create Archive of Directory

# zip -r output.zip /var/log

Extract Archive

# unzip output.zip

Tool 2 – Tar

Tar is the another most popular command line archiving utility for Linux systems.

Create Archive of File

# tar -cf output.tar /var/log/*.log

Create Archive of Directory

# zip -cf output.tar /var/log

Extract Archive

# tar -xf output.tar

Tool 3 – Gzip

Gzip is one more tool for command line users for making archive files. Gzip also supports to take input of data as standard input or through pipe and create zip file.

Create Archive of File

# gzip -k access.log

Create zip file of piped data

# cat /var/log/messages | gzip > messages.gz

Extract Archive

# gunzip access.log.gz

Combined – Tar + Gzip

Tar also combined gzip program to enable higher compression level of files. Uisng tar with gzip created files extension will be .tar.gz.

Create Archive of File

# tar -czf output.tar.gz /var/log/*.log

Create Archive of Directory

# zip -czf output.tar.gz /var/log

Extract Archive

# tar -xzf output.tar.gz

The post 3 Most Popular Tools to Archive Files and Directories in Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/popular-tools-to-archive-files-and-directories-in-linux/feed/ 0
How to Extract tar.gz File in Linux https://tecadmin.net/how-to-extract-tar-gz-file/ https://tecadmin.net/how-to-extract-tar-gz-file/#respond Sun, 05 Oct 2014 09:49:22 +0000 https://tecadmin.net/?p=6329 A .tar.gz is compression format commonly used in the Unix based operating system. The tar.gz file format is the combination of TAR packaging followed by the GNU zip (gzip) compression. The tar command is used to compress multiple files and create a single archive file. It creates highly compressed file to save more disk space. [...]

The post How to Extract tar.gz File in Linux appeared first on TecAdmin.

]]>
A .tar.gz is compression format commonly used in the Unix based operating system. The tar.gz file format is the combination of TAR packaging followed by the GNU zip (gzip) compression.

The tar command is used to compress multiple files and create a single archive file. It creates highly compressed file to save more disk space. The same command is also used to extract, maintain, or modify tar archives via command line .

This tutorial will help you with the followings:

  1. How to extract .tar.gz file
  2. How to create a .tar.gz file
  3. And list .tar.gz file content without extracting

How to extract .tar.gz file

Use tar command with -x (extract), -z (gzip) and -f for the file name. The below example command will extract content of Backup.tar.gz file in the current directory.

tar -xzf Backup.tar.gz 

This will silently extract .tar.gz file in current directory. Use -v to enable verbose mode.

To extract content to other directory us option -C (capital C). This will change the extract location of files.

tar -xvzf Backup.tar.gz -C /opt  

The above command will extract all files under /opt directory.

How to create .tar.gz file

Use -c command line option to create a tar archive. The -z option is used to compress with TAR + Gzip.

The following command will compress all files, directories and subdirectories under the /var/log directory.

tar -czf Backup.tar.gz /var/log  

In case of absolution path, GNU tar also maintains the directory structure but skipped root (/) in file system. In the above case the archive contains structure as “var/log/” and all files under the log directory.

You can also specify multiple files names to add them in single archive.

tar -czf Backup.tar.gz *.log /backup/*.sql /opt/list.txt 

The above command will archive all files with .log extension in current directory. All files with .sql in /backup directory and /opt/list.txt. As the absolute path is used, it will remove the / directory. You will see the message like “tar: Removing leading `/’ from member names”

How to list .tar.gz file content

Use -t option to list all files compressed under a .tar.gz file without extracting them. For example, execute on previously created compressed files:

tar -tvzf Backup.tar.gz  


-rw-r--r-- root/root    119783 2019-12-31 06:22:22 file1.txt
-rw------- root/root    863287 2019-08-14 17:35:58 anaconda.log
-rw------- root/root         0 2019-12-29 02:17:27 boot.log
-rw-r--r-- root/root         0 2019-12-29 02:17:26 kdm.log
-rw-r--r-- root/root     25643 2019-12-29 01:12:35 Xorg.0.log
-rw-r--r-- root/root     11380 2019-11-24 17:35:39 yum.log

Conclusion

This tutorial explained you to how to create and extract .tar.gz file on Linux command line. It also helped you to view .tar.gz file content without extracting it.

For more details visit tar command man pages.

The post How to Extract tar.gz File in Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-extract-tar-gz-file/feed/ 0
Linux tar Command with Useful Practical Examples https://tecadmin.net/linux-tar-command-with-useful-practical-examples/ https://tecadmin.net/linux-tar-command-with-useful-practical-examples/#respond Tue, 16 Apr 2013 06:59:51 +0000 https://tecadmin.net/?p=872 GNU TAR (Tape ARchive) combines multiple files together into a single tape or disk archive, and can restore individual files from the archive. Here are some Linux tar command with Useful practical examples. Some useful command line switches are given below, which are used in this article. -c => create a new archive file -v [...]

The post Linux tar Command with Useful Practical Examples appeared first on TecAdmin.

]]>
GNU TAR (Tape ARchive) combines multiple files together into a single tape or disk archive, and can restore individual files from the archive. Here are some Linux tar command with Useful practical examples.

Some useful command line switches are given below, which are used in this article.

  • -c => create a new archive file
  • -v => show the detailed output (or progress) of command
  • -x => extract an archive file
  • -f => specify file name of an archive
  • -z => Use archive through gzip
  • -j => Use archive through bzip2
  • -J => Use archive through xz
  • -t => viewing content of archive
  • -O => Display file content on stdout
  • -r => append file to existing archive
  • -C => Use of define destination directory
  • -W => Verify a archive file

How to Create Archive using Tar

Use the following examples to create new archive file in different formats like .tar (a simple archive file), .tar.gz (gzip archive), .tar.bz2 (bzip2 archive file), and .tar.xz (xz archive file).

1. Create .tar archive file – Compress all content of /var/www directory to a archive.tar file including all subdirectories.

tar -cvf archive.tar /var/www

2. Create .tar.gz archive file – Compress all content of /var/www directory to a archive.tar.gz file including all subdirectories. This will create higher compressed file that above.

tar -zcvf archive.tar.gz /var/www

3. Create .tar.bz2 archive file – Compress all content of /var/www directory to a archive.tar.bz2 file including all subdirectories. This takes more time to compress than others and provides the highest compressed file that above.

tar -jcvf archive.tar.gz /var/www

4. Create .tar.xz archive file – Compress all content of /var/www directory to a archive.tar.xz file including all subdirectories. This takes more time to compress than others and provides the highest compressed file that above.

tar -Jcvf archive.tar.xz /var/www

How to Extract Archive using Tar

Use the following commands example to extract archive files. In this section each example has two commands, the First command will extract content in the current directory and the second command will extract file content in the specified directory with -C option.

5. Extract .tar archive file –

tar -xvf archive.tar
tar -xvf archive.tar -C /tmp/

6. Extract .tar.gz archive file –

tar -zxvf archive.tar.gz
tar -zxvf archive.tar.gz -C /tmp/

7. Extract .tar.bz2 archive file –

tar -jxvf archive.tar.bz2
tar -jxvf archive.tar.bz2 -C /tmp/

8. Extract .tar.xz archive file –

tar -Jxvf archive.tar.xz
tar -Jxvf archive.tar.xz -C /tmp/

How to List Archive File Content with Tar

You can list all the content inside a tar (Tape ARchive) file without extracting it. It helps the user to check available files in an archive and save users time.

9. List .tar archive file content –

tar -tvf archive.tar

10. List .tar.gz archive file content-

tar ztvf archive.tar.gz

11. List .tar.bz2 archive file content-

tar jtvf archive.tar.bz2

12. List .tar.xz archive file content-

tar Jtvf archive.tar.xz

How to Update Tar Archive File

You can use -u option to simply update archive file. Using this option, it will only append files newer than the copy in the archive file.

13. Update .tar archive file –

tar -uvf archive.tar /var/www

14. Update .tar.gz archive file –

tar -zuvf archive.tar.gz /var/www

15. Update .tar.bz2 archive file –

tar -juvf archive.tar.bz2 /var/www

16. Update .tar.xz archive file –

tar -Juvf archive.tar.xz /var/www

Other Useful Archive File Commands

Below are some more useful options available for handling tape archive files. Below examples are shown in the simple .tar file. You can use them with .tar.gz (-z option), .tar.bz2 (-j option) and .tar.xzf (-J option).

17. Display file content – use -O followed by filename, this will display content of specified file.

tar -uvf archive.tar -O backup/index.html

18. Adding file to archive – use -r followed by filename to add more files to existing archive file.

tar -rvf archive.tar add_new_file.txt

Conclusion

In this tutorial you have learned about Linux tar command with useful practical examples.

For more details, visit: http://www.gnu.org/software/tar/manual/tar.html

The post Linux tar Command with Useful Practical Examples appeared first on TecAdmin.

]]>
https://tecadmin.net/linux-tar-command-with-useful-practical-examples/feed/ 0