Skip to content

Instantly share code, notes, and snippets.

@jokerr
Last active September 24, 2016 13:45
Show Gist options
  • Save jokerr/bce83f41e0b4406d49c7e1b63f25375b to your computer and use it in GitHub Desktop.
Save jokerr/bce83f41e0b4406d49c7e1b63f25375b to your computer and use it in GitHub Desktop.
Various bash scripts that I've collected/written over the years

Colored Output

This script shows how you can print out various things in color from BASH script.

#!/bin/bash

NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)

function error() {
        echo -e "$RED$*$NORMAL"
}

function warn() {
        echo -e "$YELLOW$*$NORMAL"
}

function debug() {
        if [[ $DEBUG ]]
        then
                echo -e "$GREEN>>>$*$NORMAL"
        fi
}

error "danger!"
warn "caution"
echo "normal"
DEBUG=true
debug "debug me"

Find duplicate files by MD5

find . -type f -exec md5 '{}' ';' | sort -k 4| uniq -f 3 -d | sed -e "s/.*(\(.*\)).*/\1/" | sort
#!/bin/bash
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function error() {
echo -e "$RED$*$NORMAL"
}
function warn() {
echo -e "$YELLOW$*$NORMAL"
}
function debug() {
if [[ $DEBUG ]]
then
echo -e "$GREEN>>>$*$NORMAL"
fi
}
error "danger!"
warn "caution"
echo "normal"
DEBUG=true
debug "debug me"
#!/bin/bash
if [ -z "$1" ]
then
echo "missing class"
exit 1
fi
echo ${1}
for file in `find . -type -f -name "*.jar"`
do
if [ `grep -c $class $file` -gt 0]
echo "\n"
echo "Found in $file:"
jar tf $file | grep $class
echo "\n"
fi
done
find . -type f -exec md5 '{}' ';' | sort -k 4| uniq -f 3 -d | sed -e "s/.*(\(.*\)).*/\1/" | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment