Can files in gzipped tarballs be extracted without paths?

Jamon Camisso jamon.camisso-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Thu Jul 31 01:27:55 UTC 2014


On 2014-07-30 9:05 PM, Walter Dnes wrote:
>   Situation;
> * I download a *.tar.gz file
> * I know that it has a tarred subdirectory containing a bunch of files
> * I want the files in the subdirectory extracted directly to the current
>   directory.
> 
>   E.g. if the tarball has subdirectory foo with files foo/file1,
> foo/file2 foo/file2, etc, I want to be able to extract file1, file2, and
> file3 directly.  Right now, I dive into the tarball with mc (Midnight
> Commander), and "mark and copy" the files in the virtual file system.
> unzip has the -j option to "junk" the directorie structure, and unzip
> all files in the archive into one directory.  Is something similar
> available with tar?

Try using --strip-components. You'd want to strip 1 leading component to
get all the files into your cwd.

If you want tar to extract to a directory you can use -C, for example:

tar xvzf your-tar-file.tar.gz --strip-components=1 -C /tmp/bar foo

You'd end up with file1, file2, file3 in /tmp/bar based on specifying
you only want to extract the foo directory, and that you want to strip
the first component of the path of the extracted file/directory.

Cheers, Jamon
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list