Search code examples
linuxansibleyamlunzip

How to extract only one file from war file?


I am working on a shell command for Ansible in Linux, I have a .war file, and I need only tasks.properties file from it. I tried the below, but it extracts the parent directory folder WEB-INF, so, I get WEB-INF/sub/test.properties extracted, when I just need the test.properties outside

unzip test.war "*test.properties*" 

I also tried

jar xf test.war test.properties

This also extracted the main folder, and WEB-INF/sub/test.properties.

When I ls, I just want test.properties to appear in the location where I am running this, any suggestions on how to do that?


Solution

  • The -j flag is exactly what you need:

    unzip -j test.war "*test.properties*" 
    

    From the docs:

    -j

    junk paths. The archive's directory structure is not recreated; all files are deposited in the extraction directory (by default, the current one).