*Nix Commands

Create package

Below command will create a package from files located in different directories & files with and without preserving the directory structure.

-C is used to change directory and then include the following file. Without it the directory structure is preserved. The files and folder appear in the root directory

tar -czf project-name.tar.gz ./bin/startserver.sh -C build/libs project-1.0.jar -C ../../lib/properties log4j2-project.xml

String Operations

Check null value in strings

// Check null value in string
my_var="nixCraft"
if [ -z "$my_var" ]
then
      echo "\$my_var is NULL"
else
      echo "\$my_var is NOT NULL"
fi

Split Strings

// Split and get the last results
$ foo=hadoop-mapreduce-client-core-2.7.3
$ echo ${foo##*-}

// Split and get a substring    

Miscellaneous

Find jar versions of all jars in a folder from its manifest file ls | xargs -I {} 'unzip {} META-INF/MANIFEST.MF; version=`cat META-INF/MANIFEST.MF | grep "Implementation-Version\|Bundle-Version" | sed "s/Bundle-Version: //" | sed "s/Implementation-Version: //"`;echo {} -------- $version >> jar-version.txt'

Last updated