![]() ![]() 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 tar.gz files I downloaded wouldn't work because they didn't actually use gzip compression despite the filename.Let us now look at some examples below. Note that because it's primarily designed as a preprocessor for less, it won't output anything if it doesn't recognise the file type. cmd &>/dev/null (or cmd &>file to redirect both stderr and stdout to a file). If you are using bash then you can shorten it with: &>/dev/null (or >&/dev/null ). For files matching the tar.gz extension, we can see that it uses tar tzvf under the hood along with the -force-local option to disable an obscure feature of tar that would otherwise confuse colons in the filename with a command to use a remote tape drive: *.tar.gz|*.tgz|*.tar.z|*.tar.dz) Just in case you want to avoid output sent to stderr and stdout, you can add >/dev/null 2>&1 to the command shown in this answer. If feeling adventurous, take a peak at vi /usr/bin/lesspipe to see what commands it uses. It is called by the less command ( see Oli's answer) as an input preprocessor if the $LESSOPEN environment variable is set appropriately. rw-rw-r- ubuntu/ubuntu 7 05:32 example/ubuntu.txt rw-rw-r- ubuntu/ubuntu 7 05:32 example/ask.txt $ lesspipe ĭrwxrwxr-x ubuntu/ubuntu 0 05:32 example/ Lesspipe is a shell script installed by default as part of the less package that can list the contents of a tar.gz archive, as well as a range of other common archive file formats. You can then list the contents of any archive: $ list_archive.sh foo.rar foo.tbz foo.zipĠ 8 0% 30-03-15 19:29 -rw-r-r- 00000000 m3b 2.9Ġ 0 0% 30-03-15 19:29 drwxr-xr-x 00000000 m0 2.0Īnd since someone mentioned that lesser editor, naturally, emacs can also do this: Save that script in your PATH and make it executable. Type zip >/dev/null 2>&1 & zip -sf "$file"||Įcho "Unknown extension: '$ext', skipping." Type rar >/dev/null 2>&1 & rar v "$file"|| Type tar >/dev/null 2>&1 & tar tf "$file"|| # have extensions like tar.bz2 or tar.gz etc. With all this in mind, you could write a little script that uses the appropriate command depending on the extension of the file you give to it: #!/usr/bin/env bashįor file in "\n-\nArchive '%s'\n-\n" "$file" That's most of the more popular archive formats. Since you marked it first, all copied your action. pacodelumberg at 17:12 1 Rinzwind: Please give some time before marking any post as duplicate. RAR 4.20 Copyright (c) 1993-2012 Alexander Roshal P7zip Version 9.20 (locale=en_US.utf8,Utf16=on,HugeFiles=on,4 CPUs) Tar/ tar.gz/ tgz/ tar.xz/ tar.bz2/ tbz files $ tar tf foo.tgzħ-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov Most (de)compression programs have a flag that lists an archive's contents. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |