Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
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:
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/
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
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/
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
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
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
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
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/
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