0

Possible Duplicate:
tar – extract discarding directory structure

I have a tar file that include sub-directories each has several files. I need to extract all those files into one directory. Any help?

Labibah
  • 103
  • 1
  • 3

1 Answers1

0

Operating system not stated. Assuming some *nix-like variant.

Assuming TAR file tarfile.tar in the current directory:

mkdir temp dirwithfiles
tar xvf tarfile.tar -C temp
find temp -type f -exec mv -i {} dirwithfiles \;
rm -r temp

This will extract the full directory structure, then move all files within to the dirwithfiles directory.

Note mv -i since there might be several files with the same filename that need to be selected from.

Daniel Andersson
  • 23,895
  • 5
  • 57
  • 61
  • It's almost uncanny how similar this is to the accepted answer in the question that was later linked as a duplicate. It's obvious enough to not qualify for a patent, though, so I think I'm in the clear. – Daniel Andersson Aug 22 '12 at 09:56