72 lines
2.7 KiB
Plaintext
72 lines
2.7 KiB
Plaintext
# Functions gathered from around the internet
|
|
extract () { # Extracts most common compressed files
|
|
if [ -f $1 ] ; then
|
|
case $1 in
|
|
*.tar.bz2) tar xjf $1 ;;
|
|
*.tar.gz) tar xzf $1 ;;
|
|
*.bz2) bunzip2 $1 ;;
|
|
*.rar) rar x $1 ;;
|
|
*.gz) gunzip $1 ;;
|
|
*.tar) tar xf $1 ;;
|
|
*.tbz2) tar xjf $1 ;;
|
|
*.tgz) tar xzf $1 ;;
|
|
*.zip) unzip $1 ;;
|
|
*.Z) uncompress $1 ;;
|
|
*) echo "'$1' cannot be extracted via extract()" ;;
|
|
esac
|
|
else
|
|
echo "'$1' is not a valid file"
|
|
fi
|
|
}
|
|
maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
|
|
makezip() { zip -r "${1%%/}.zip" "$1" ; }
|
|
psgrep() {
|
|
if [ ! -z $1 ] ; then
|
|
echo "Grepping for processes matching $1..."
|
|
ps aux | grep $1 | grep -v grep
|
|
else
|
|
echo "!! Need name to grep for"
|
|
fi
|
|
}
|
|
gpass() { # Generates passwords
|
|
local l=$1
|
|
[ "$l" == "" ] && l=20
|
|
tr -dc A-Za-z0-9-!@%^*_ < /dev/urandom | head -c ${l} | xargs
|
|
}
|
|
|
|
#up() { # Usage: up <Number of directories>. Blank for up one dir.
|
|
# local d=""
|
|
# limit=$1
|
|
# for((i=1 ; i <= limit ; i++)); do
|
|
# d=$d/..
|
|
# done
|
|
# d=$(echo $d | sed 's/^\///')
|
|
# if [ -z "$d" ]; then
|
|
# d=..
|
|
# fi
|
|
# cd $d
|
|
#}
|
|
#dirsize - finds directory sizes and lists them for the current directory
|
|
dirsize (){
|
|
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
|
|
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
|
|
egrep '^ *[0-9.]*M' /tmp/list
|
|
egrep '^ *[0-9.]*G' /tmp/list
|
|
rm -rf /tmp/list
|
|
}
|
|
myps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }
|
|
ii() { # Get current host related info.
|
|
echo -e "\nYou are logged on ${BRed}$HOST"
|
|
echo -e "\n${BRed}Additionnal information:$NC " ; uname -a
|
|
echo -e "\n${BRed}Users logged on:$NC " ; w -hs | cut -d " " -f1 | sort | uniq
|
|
echo -e "\n${BRed}Current date :$NC " ; date
|
|
echo -e "\n${BRed}Machine stats :$NC " ; uptime
|
|
echo -e "\n${BRed}Memory stats :$NC " ; free
|
|
echo -e "\n${BRed}Diskspace :$NC " ; mydf / $HOME
|
|
echo -e "\n${BRed}Local IP Address :$NC" ; my_ip
|
|
echo -e "\n${BRed}Open connections :$NC "; netstat -pan --inet;
|
|
echo
|
|
}
|
|
|
|
|