![]() ![]() 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. setfacl -R -m o::x /home/ers/directory Gives group rwx permissions by default, recursively. setfacl -R -m g::rwx /home/ers/directory Revokes read and write permission for everyone else in existing folder and subfolders. Img 04: Extract tar.bz2 Files to Different Directory Example 4: Extract Only Specific or Selected Files from Tar Archive Gives group read,write,exec permissions for currently existing files and folders, recursively. # 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 However, any scheme for making unique directory names would be sufficient.Let us now look at some examples below. # extract the file into its own directoryĪbove I extract into directories named after the tarball. # make a directory named after the tar file, minus extension # strip any leading path information from the file name Per comments, here's a method for extracting tarballs into subdirectories. If you had a file named foo\bar then read without -r would not read it correctly. When performing a while read loop you almost always want to use read -r, which will prevent backslashes in the input from being interpreted as escape sequences. Example: A file named monthly will be interpreted as tar xzf monthly and you will get an error because the archive monthly does not exist.īecause echo will mangle file names, specifically ones with spaces in the name. ![]() This is still not safe, but it's safer.īecause a file with spaces in the name, among other things, will be interpreted in ways you do not expect. If you must use ls for this you should be careful to use ls -1 and then be careful that you treat newline and only newline as a record seperator. maxdepth 1 -type f -name '*.tar.gz' -exec tar xzf \ `īecause ls will clobber certain characters in file names (ie, it is not safe). ![]() The other acceptable answer would be to use find find. The correct answer is this: for file in *.tar.gz do Most of the answers so far do not account for unusual file names e.g., those containing spaces, newlines or other special characters). If you specify additional names on the command line they are interpreted as files to extract from the specified. tar file at a time: the one specified with f. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |