Search The Query
  • Home
  • Linux
  • TIP : Extract a Tar File Without the Leading or Container Directory

TIP : Extract a Tar File Without the Leading or Container Directory

ship containers

You can do without the leading directory.

Photo by frank mckenna on Unsplash

It is possible to extract a tar file without the first directory by using the — strip-components flag. This can be useful when downloading a tar file from the Internet; for example, the Adopt OpenJDK tar file contains the following directory tree structure:

[root@localhost tt]# tar mtvzf OpenJDK8U-jdk_x64_linux_hotspot_8u345b01.tar.gz|awk '{print $6}'jdk8u345-b01/
jdk8u345-b01/jre/
jdk8u345-b01/jre/lib/
jdk8u345-b01/jre/lib/ext/
jdk8u345-b01/jre/lib/ext/nashorn.jar
jdk8u345-b01/jre/lib/ext/zipfs.jar
jdk8u345-b01/jre/lib/ext/localedata.jar
jdk8u345-b01/jre/lib/ext/dnsns.jar
jdk8u345-b01/jre/lib/ext/sunpkcs11.jar
jdk8u345-b01/jre/lib/ext/sunjce_provider.jar
jdk8u345-b01/jre/lib/ext/jaccess.jar
jdk8u345-b01/jre/lib/ext/meta-index
jdk8u345-b01/jre/lib/ext/cldrdata.jar
jdk8u345-b01/jre/lib/ext/sunec.jar
jdk8u345-b01/jre/lib/psfontj2d.properties
jdk8u345-b01/jre/lib/management-agent.jar
jdk8u345-b01/jre/lib/hijrah-config-umalqura.properties
jdk8u345-b01/jre/lib/calendars.properties
jdk8u345-b01/jre/lib/net.properties…

The jdk8u345-b01 directory contains everything. If you wish to extract this tar file without the jdk8u345-b01 folder, you can use the “ –strip-components=1” option to skip the first directory.

tar --strip-components=1 -xvzf OpenJDK8U-jdk_x64_linux_hotspot_8u345b01.tar.gz

This will extract all files and subdirectories without the container folder.

Sweet, right?

Leave a Reply

Related blogs
rambox product image
Streamline Your Workflow: The Ultimate Productivity Browser for App Consolidation
MadMachineAug 26, 2024

Unlock your potential and simplify your digital life with this innovative Productivity Browser designed…