I have a tar.gz file from which I have to extract only the files in current directory without creating the whole structure.

For example:

tar.gz contains below files,


the tar.gz is present in /u02. So when extracting I want file1 through file10 coming under /u02 instead, the whole directory structure is getting created under /u02

2 Answers 2


Since you seem to have a fixed number of path components, pass --strip-components=3 to tar to remove /u01/app/oracle while extracting to /u02

For a variable number of components, use the --transform flag instead. Something along the lines of --transform='s,^\([^/][^/]*/\)\+,,'

  • Ok, this will work when tar contains files from one location. But this tar has files from 2 different locations with varying path lengths. I did not mention that in example. Mar 14, 2017 at 5:39
  • @GirishSunkara, see edit
    – iruvar
    Mar 14, 2017 at 5:53

With the standard pax command:

gunzip < file.tar.gz | pax -r's|.*/||p'
  • That works!!! exactly what I am looking for... Can you please explain the logic how it is doing it? Mar 14, 2017 at 7:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .