Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create and Manage Archives in Linux

Archives are crucial for efficiently managing and storing multiple files and directories in a single file. This is particularly important for backups, file transfers, and organizing data. In the Linux environment, the tar command is predominantly used for creating and managing archives. This article will guide you through the process of creating, extracting, and managing archives using tar, along with some practical examples.

Examples:

  1. Creating an Archive:

    To create an archive of a directory named my_folder, you can use the following command:

    tar -cvf archive_name.tar my_folder/
    • -c stands for "create".
    • -v stands for "verbose", which means it will list the files being processed.
    • -f specifies the filename of the archive.

    Example:

    tar -cvf my_archive.tar my_folder/
  2. Extracting an Archive:

    To extract an archive, use the -x option:

    tar -xvf archive_name.tar
    • -x stands for "extract".

    Example:

    tar -xvf my_archive.tar
  3. Creating a Compressed Archive:

    To create a compressed archive using gzip, you can add the -z option:

    tar -czvf archive_name.tar.gz my_folder/
    • -z stands for "gzip compression".

    Example:

    tar -czvf my_compressed_archive.tar.gz my_folder/
  4. Extracting a Compressed Archive:

    To extract a gzip-compressed archive, use:

    tar -xzvf archive_name.tar.gz

    Example:

    tar -xzvf my_compressed_archive.tar.gz
  5. Listing the Contents of an Archive:

    To list the contents of an archive without extracting it, use the -t option:

    tar -tvf archive_name.tar
    • -t stands for "list".

    Example:

    tar -tvf my_archive.tar
  6. Adding Files to an Existing Archive:

    To add files to an existing archive, use the -r option:

    tar -rvf archive_name.tar new_file
    • -r stands for "append".

    Example:

    tar -rvf my_archive.tar new_file.txt
  7. Deleting Files from an Archive:

    To delete files from an archive, use the --delete option:

    tar --delete -f archive_name.tar file_to_delete

    Example:

    tar --delete -f my_archive.tar file_to_delete.txt
  8. Creating a Bzip2 Compressed Archive:

    To create a bzip2 compressed archive, use the -j option:

    tar -cjvf archive_name.tar.bz2 my_folder/
    • -j stands for "bzip2 compression".

    Example:

    tar -cjvf my_bzip2_archive.tar.bz2 my_folder/
  9. Extracting a Bzip2 Compressed Archive:

    To extract a bzip2 compressed archive, use:

    tar -xjvf archive_name.tar.bz2

    Example:

    tar -xjvf my_bzip2_archive.tar.bz2

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.