0

How do I extract only files from a directory in a tar archive? I need to extract all the files in the directory, not specific files. For example, with a tar archive of this structure:

wordpress
 --wp-admin
 --wp-content
 --wp-includes
 --index.php
 --license.txt
 --readme.html

I want to extract only the 3 (or more) files in the wordpress directory not the sub-directories.

Note that the other solutions I could find on this site are about extracting specific files. My question is about extracting all files.

  • I don't want to extract specific files. I want to extract all the files in the directory. It is not a duplicate. – Chetan Crasta Jun 10 '17 at 13:43
  • could there be folders with . in their names within the archive (like folder.suff)? – RomanPerekhrest Jun 10 '17 at 13:47
  • Good question. I think the --no-wildcards-match-slash option prevents any sub-directories from being matched. I haven't tested this, so I can't confirm it, though. – Chetan Crasta Jun 10 '17 at 14:05
  • @ChetanCrasta, I've tested those options --wildcards --no-wildcards-match-slash and they do not prevent subdirectories extraction at all – RomanPerekhrest Jun 10 '17 at 14:10
  • Do you mean it doesn't work with subdirectories of type folder.name? Or with all sub-directories? I can confirm that the solution given works on Debian. – Chetan Crasta Jun 10 '17 at 14:57
-1

This will extract all the files in a directory in a tar file, without going into the sub-directories:

tar --wildcards --no-wildcards-match-slash -xvf file.tar.gz directory_in_tar/*.*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.