![]() tar -xzvf ~/Īlso for uncompressed and extract files with bz2 files, you can use this command. If you want to extract a gzip file you can use below command. To extract files from a tar archive, issue the following command. tar -cJf ~/ ~/data/ Tar command Example for uncompressed and extracting files tar -cjf ~/2 ~/data/Ĭreate a tar file and xzip compression. tar -czf ~/ ~/data/Ĭreate a tar file with bzip compression. tar -cf data_archive.tar ~/data Compress an Archive using GzipĬreate a file with tar and gzip command. Tar command Example for archive and compressing files Creating an ArchiveĬreate a file without using the standard output redirection. Now we show you some example for tar command. Recommended Article: How to setup a web server with a CWP hosting panel Therefore -cvf will perform as expected while -cfv will fail. The -f option needs to be the last option, and thus appear closest to the name of the file that it specifies. The order of options is sometimes important. For instance the following command will output a list of files as they are added to the archive. You may also add a -v option to increase the verbosity of some commands. The following command is equivalent to the previous command. You may choose to bypass the standard output functionality with the -f option. tar -c ~/data > data-archive.tarīy default, tar sends the contents of the archive file to the standard output, you can use this to further process the archive you create. To create an archive of all the files in the directory ~/data, use the following command. This will extract (-x) the archive specified by the file (-f) named on the prompt. Given the tar file ~/archive.tar, the following command can be used to extract the contents of this file into the current directory. The complexity of tar does not derive from its basic form, but rather from the number of options and settings that you can use to create and interact with archives. Using tar command on Linux Extract archive file with Tar Tar command Example for uncompressed and extracting files.Tar command Example for archive and compressing files.If you like this article, please don't forget to share it with friends through your favorite social network. If you have any suggestions, feedback, or comment about this article, let me know. The following image shows the SELinux context of the original files, extracted files without -selinux option, and extracted files with the -selinux option.Īs you can see in the above image, if the option -selinux is used when creating and extracting an archive file, the SELinux contexts of the files are preserved. ![]() Now compare the SELinux contexts of the extracted files with the SELinux contexts of the original files. The following image shows the above exercise step by step along with the required commands and their output. When extracting the archived file that was created with the option -selinux, specify the same option -selinux before specifying the options -xvf.Switch to both directories one-by-one and extract the copied archive files.Copy both archive files into the directories (reg and ext) that we created in the first step, respectively.When creating the second archive file, specify the option -selinux before specifying the options -cvf. Create two archive files by using the files which are created in the above step.Switch to the directory /var/www/html and create a few files.Create two directories for the practice: reg and ext.Let's take an example, to understand how it works practically. For example, if you want to preserve the SELinux contexts, use the option -selinux. If we want to preserve the extended attributes, we have to instruct the tar command to do the same. Extended attributes contain the metadata information such as access control list, SELinux, etc.īy default, the tar command doesn't retrain the extended attributes. Regular attributes contain essential information such as owner info, access permission, created date, etc. There are two types of attributes regular attributes and extended attributes. Preserving SELinux context when adding files to the archiveįile attributes are used to store additional information about the file. The following image a few more examples of how to use the correct options to decompress and extract compressed archived files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |