![]() ![]() If you find this guide helpful or have more information or additional ideas, you can give me a feedback by posting a comment. That is it with extracting tar files to a specific directory and also extracting specific files from a tar file. Img 05: Extract Specific Files From Tar Archive Summary # tar -xvf etc.tar etc/issue etc/nf etc/mysql/ -C /backup/tar_extracts/ In the next example, I will extract specific files out of a tar file to a specific directory as follows: # mkdir /backup/tar_extracts The tar utility also allows you to define the files that you want to only extract from a. ![]() Img 04: Extract tar.bz2 Files to Different Directory Example 4: Extract Only Specific or Selected Files from Tar Archive # tar -jvxf documents.tbz2 -C /tmp/tar.bz2/ Now we will be unpacking the documents.tbz2 files to /tmp/tar.bz2/ directory. tbz2 Files to Different DirectoryĪgain repeating that you must create a separate directory before unpacking files: # mkdir -p /tmp/tar.bz2 tgz Files to Different Directory Example 3: Extract tar.bz2. Now we will extract the contents of documents.tgz file to separate /tmp/tgz/ directory. tgz Files to Different Directoryįirst make sure that you create the specific directory that you want to extract into by using: # mkdir -p /tmp/tgz Img 02: Extract Tar Files to Specific Directory Example 2: Extract. # tar -xvf articles.tar -directory /tmp/my_articles/ Let me also use the -directory option instead of -c for the example above. In the above example I used the -v option to monitor the progress of the tar extraction. Img 01: Extract Tar Files to Different Directory To extract the files in articles.tar to /tmp/my_article, I will run the command bellow: # tar -xvf articles.tar -C /tmp/my_article/ You can include the -p option to the above command so that the command does not complain. Let me start by creating the /tmp/my_article directory using the command below: # mkdir /tmp/my_article Always make sure that the directory into which you want to extract tar file exists. In the first example, I will extract the files in articles.tar to a directory /tmp/my_article. Example 1: Extracting tar Files to a Specific Directory So, back to your command, since you are in /tmp already, you can just discard the -C option (since by default tar will extract files in the current working directory) and just add -strip-components=2: tar -strip-components=2 -xfvz us now look at some examples below. % tar -C path -strip-components=2 -zxf bash-4.3.tar.gz bash-4.3/doc/bash.html % tar -tf bash-4.3.tar.gz | grep -F 'bash.html' To extract a single file / folder from an archive that uses relative paths without its ancestors into a relative path you'll need two options: -C and -strip-components=N: in the example below the archive bash-4.3.tar.gz uses relative paths and contains a file bash-4.3/doc/bash.html which is extracted into a relative path path ( -C specifies the directory in which to extract the files, -strip-components=2 specifies that the parent and the parent of the parent of the extracted files should be ignored, so in this case only bash.html will be extracted into the target directory): % tree When I do the following command I would prefer if I could have it unpack starting at /directories/ and not /wordpress with the goal of installing wordpress in the root of my html directory. And you can repeat this -C hanging directories. Specifying filename arguments after the tarfile name restricts the extraction to just those files or directories. The -C option means to change to the specified directory before doing the extraction. Within it is the following structure /wordpress/dirtories/files. I think this should do it: tar -xzf -C /locationX folder1 -C /locationY folder2. Whether an archive uses relative paths can be checked by running tar -tf archive | head -n 1, which will print the path of the first file in the archive if that file's path is a relative path, all the files in the archive use relative paths: % tar -tf bash-4.3.tar.gz | head -n 1 Un-tar a specific directory inside of a tar. GNU tar by default stores relative paths. Since you are in /tmp already, you can just discard the -C option (since by default tar will extract files in the current working directory) and just add -strip-components=2: tar -strip-components=2 -xfvz folder/in/archive ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |