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:


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.

  • 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
  • you want to extract specific files -- the ones that aren't subdirectories; does the --files-from option not work for you? You'd list the contents of the tar file, then filter for only the wordpress folder, then exclude the sub-folders, then pass that file to tar. – Jeff Schaller Jun 12 '17 at 20:29

I could see this question already answered/posted in the following link,


| improve this answer | |

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/*.*
| improve this answer | |

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.