archive – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Wed, 26 Oct 2022 03:29:50 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.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 Unzip (Extract) GZ File in Linux https://tecadmin.net/extract-gz-file-in-linux-command/ https://tecadmin.net/extract-gz-file-in-linux-command/#comments Tue, 04 Nov 2014 06:50:50 +0000 https://tecadmin.net/?p=6334 A GZ file is a compressed archive that uses the gzip compression algorithm (GNU zip). This format was created to replace compression formats on UNIX systems. It may contain multiple compressed files, directories, and stubs. This compression algorithm is more popular for compressed web pages to reduce page loading time. The GNU zip compressed file [...]

The post How to Unzip (Extract) GZ File in Linux appeared first on TecAdmin.

]]>
A GZ file is a compressed archive that uses the gzip compression algorithm (GNU zip). This format was created to replace compression formats on UNIX systems. It may contain multiple compressed files, directories, and stubs. This compression algorithm is more popular for compressed web pages to reduce page loading time.

The GNU zip compressed file uses .gz or .z extension. In this article, you will learn how to decompress (Unzip or extract) a GZ file via the command line.

Extracting GZ file:

We can use gunzip command to decompress a .gz file on Linux and macOS systems.

gunzip file_name.gz 

A .gz file is compressed with gzip command line. That can also be used to decompress it with -d parameter.

gzip -d file_name.gz 

Both the above commands retrieve back the original file and remove the .gz extension from file name.

Once you have decompressed a .gz file, it will no longer avaialble. But, if you want to keep the archive file use -k or --keep option with unzip command.

gzip -d -k file_name.gz          ## OR
gunzip -k file_name.gz 

Example

  • First, use the following command to create gzip (.gz) archive of the access.log file. Keep remembering that the below command will remove the original file.
    gzip access.log 
    
  • Above command will create a archive file named access.log.gz in current directory.
    ls -l access.log.gz 
    
    -rw-r--r-- 1 root root 37 Sep 14 04:02 access.log.gz
    
  • Now use gunzip command to extract the access.log.gz file using the command. This will extract the file from the archive and remove the .gz file automatically.
    gunzip access.log.gz 
    

Conclusion

In this blog post, you have learned about extracting a .gz on Linux or macOS system using command line. You can also enable Gzip compression in Apache.

The post How to Unzip (Extract) GZ File in Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/extract-gz-file-in-linux-command/feed/ 4
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