# print this months calendar out
cal
# print date and time
# date +"%A, %B %-d, %Y"
#print OS + CPU
uname -rvp
# List these alias Commands, this file...
alias commands='nice -n 17 less ~/.bash_aliases'
#Check if Root
if [ $UID -ne 0 ]; then
# This is not a root user:
echo "Welcome, " `whoami`
echo "This is a protected system! All access is logged."
alias reboot='sudo reboot'
alias upgrade='sudo apt-get upgrade'
else
# Wow, got root:
echo "You are logged in as an admin becareful! This is a restricted system, this will be logged."
alias upgrade='apt-get upgrade'
fi
#cheat-sheet
chmod-cheat() {
echo "chmod =:"
echo "1 = execute only"
echo "2 = write only"
echo "3 = write and execute (1+2)"
echo "4 = read only"
echo "5 = read and execute (4+1)"
echo "6 = read and write (4+2)"
echo "7 = read and write and execute (4+2+1)"
echo "qmod =:"
echo "web) 0644"
echo "safe) 0640"
echo "sbin) 0110"
echo "bin) 0111"
echo "exe) 0111"
echo "+w) 0660"
echo "fullwrite) 0666"
echo "readonly) 0440"
echo "+777) 777"
}
qmod() {
if [ -e "$2" ]; then
if [ -n "$1" ]; then
if [ -d "$2" ] && [ "$3" == "-R" ]
then
OPTION="-R"
else
OPTION=""
fi
case $1 in
web) /bin/chmod $OPTION 0644 "$2" ;;
safe) /bin/chmod $OPTION 0640 "$2" ;;
sbin) /bin/chmod $OPTION 0110 "$2" ;;
bin) /bin/chmod $OPTION 0111 "$2" ;;
exe) /bin/chmod $OPTION 0111 "$2" ;;
+w) /bin/chmod $OPTION 0660 "$2" ;;
fullwrite) /bin/chmod $OPTION 0666 "$2" ;;
readonly) /bin/chmod $OPTION 0440 "$2" ;;
+777) /bin/chmod $OPTION 777 "$2" ;;
777) echo "are you sure? If so, do chmod +777 file" ;;
*) /bin/chmod $OPTION $1 "$2" ;;
esac
fi
else
if [ ! -e "$1" ]; then
echo qmod "$1" file/folder does not exists
else
chmod-cheat
fi
fi
}
#git
alias gs='git status'
alias gc='git commit -a -m'
alias mpull='git pull origin master'
alias mpush='git push origin master'
alias pull='git pull origin'
alias push='git push origin'
alias gb='git branch'
alias branch='git branch'
alias clone='git clone'
alias checkout='git checkout'
#alias gitolite='git clone gitolite:'
#tar
maketar() {
if [ -e "$1" ]; then
tar cvzf "$1.tgz" "$@"
else
if [ -e "$2" ]; then
x=""
for var in "$@"
do
if [ -e "$var" ]; then
x+=$var
x+=" "
fi
done
tar cvzf "$1.tgz" $x
else
if [ -n "$1" ]; then
tar cvzf "$1.tgz" *
else
tar cvzf all.tgz *
fi
fi
fi
}
bk() {
tar cvzf "$1".$(date +%Y%m%d-%H%M%S).tgz "$1"
}
alias untar='tar xvf'
alias ungz='tar xvfz'
#RSYNC
alias backup="nice -n 17 rsync --progress -ravz"
#apt-get
alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'
alias agu='sudo apt-get update'
alias acs='apt-cache search'
#programming
alias c='g++ -std=c++11'
alias c14='g++-4.9 -std=c++14 -pedantic -Wall -I /opt/boost_1_55_0'
alias boost='c++ -I /opt/boost_1_55_0'
# Free Basic Compiler
alias qb='fbc -lang qb '
#Networking
alias public-ip='dig +short myip.opendns.com @208.67.222.222 @208.67.220.220'
alias myip='/bin/ip -4 addr'
alias mymac='/sbin/ifconfig -a'
alias quickping='time ping -c 5'
alias fastping='ping -c 100 -i .250 -s .2'
# Lists all open UDP/TCP ports
alias ports='netstat -tulanp'
# Wake up remote PC/Sever
alias ipwake='/usr/bin/wakeonlan -i'
alias wake='echo "WakeOnLAN File with MAC and IP" && /usr/bin/wakeonlan -f'
# Firewall
alias ipt='sudo /sbin/iptables'
# Display all firewall rules
alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers'
alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers'
alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers'
alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers'
alias firewall=iptlist
#More Networking
export LAN='eth0'
export WAN='eth1'
alias dnstop='dnstop -l 5 "$LAN"'
alias vnstat='vnstat -i "$LAN"'
alias iftop='iftop -i "$LAN"'
alias tcpdump='tcpdump -i "$LAN"'
alias ethtool='ethtool "$LAN"'
export SN=`netstat -nr | grep -m 1 -iE 'default|0.0.0.0' | awk '{print \$2}' | sed 's/\.[0-9]*$//' `
alias find-servers='nmap --top-ports 10 "$SN".*'
alias find-web-servers='nmap -p 80,443,8080 "$SN".*'
alias find-file-servers='nmap -p 137,138,139,445 "$SN".*'
alias find-ssh-servers='nmap -p 22 "$SN".*'
alias find-ftp-servers='nmap -p 21 "$SN".*'
# Get Wireless Status
alias iwconfig='iwconfig wlan0'
alias wifi=iwconfig
#Ping Default Gateway
export GW=`netstat -nr | grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}'`
alias check-intenet='ping -c 5 -i .250 -s .2 "$GW"'
#Reboot routers
rebootlinksys() {
curl -u "admin:$2" "http://$1/setup.cgi?todo=reboot"
}
rebootnetgear() {
wget --output-document=/dev/null --user="admin" --password="$2" "http://$1/setup.cgi?next_file=diag.htm&todo=reboot"
}
ssh-reboot() {
if [ -n "$2" ]; then
ssh "$1"@"$2" sudo -S /sbin/reboot
else
ssh "root@$1" /sbin/reboot
fi
}
# misc functions
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract ."
else
if [ -f $1 ] ; then
NAME=${1%.*}
case $1 in
*.deb) echo Installing deb package ;;
*.rpm) echo Installing rpm package ;;
*) mkdir $NAME && cd $NAME ;;
esac
case $1 in
*.deb) sudo nice -n 17 dpkg -i $1 ;;
*.rpm) sudo nice -n 17 rpm -ivh $1 ;;
*.tar.bz2) nice -n 17 tar xvjf ../$1 ;;
*.tar.gz) nice -n 17 tar xvzf ../$1 ;;
*.tar.xz) nice -n 17 tar xvJf ../$1 ;;
*.lzma) nice -n 17 unlzma ../$1 ;;
*.bz2) nice -n 17 bunzip2 ../$1 ;;
*.rar) nice -n 17 unrar x -ad ../$1 ;;
*.gz) nice -n 17 gunzip ../$1 ;;
*.tar) nice -n 17 tar xvf ../$1 ;;
*.tbz2) nice -n 17 tar xvjf ../$1 ;;
*.tgz) nice -n 17 tar xvzf ../$1 ;;
*.zip) nice -n 17 unzip ../$1 ;;
*.Z) nice -n 17 uncompress ../$1 ;;
*.7z) nice -n 17 7z x ../$1 ;;
*.xz) nice -n 17 unxz ../$1 ;;
*.exe) nice -n 17 cabextract ../$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}
function fawk {
first="awk '{print "
last="}'"
cmd="${first}\$${1}${last}"
eval $cmd
}
# Is gzip working?
function is_gzip {
curl -I -H 'Accept-Encoding: gzip,deflate' $1 |grep "Content-Encoding"
}
#misc linux
alias hg='history|grep'
alias changed-files='find . -mtime -30 | less'
search() {
find . -name "$1" -print
}
match() {
echo "usage: match search_for_pattern file/files"
grep -n "$@" | less
}
abc() {
if [ -n "$2" ]; then
sort "$1" | grep "$2"
else
sort "$1"
fi
}
short-asc() {
abc "$@" | head
}
alias short='sed 100q'
view-long() {
sed 500q $1 | less
}
save-long() {
if [ -n "$2" ]; then
sed 500q $1 > $2
else
echo "example: save-long in-file out-file"
fi
}
head-log() {
if [ -n "$2" ]; then
head -n 2000 $1 > $2
else
head -n 2000 $1 | less
fi
}
tail-log() {
if [ -n "$2" ]; then
tail -n 2000 $1 > $2
else
tail -n 2000 $1 | less
fi
}
alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -I --preserve-root'
alias la='ls -alh'
mybackup() {
backup $@ ~/MyBackups/
}
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
alias desktop='cd ~/Desktop'
alias music='cd ~/Music'
alias videos='cd ~/Videos'
alias photos='cd ~/Pictures'
alias cd.='pwd'
alias cd..='cd ..'
alias cd,,='cd ..'
alias ..='cd ..'
alias ,,='cd ..'
alias ...='cd ../..'
alias up2='cd ../..'
alias up3='cd ../../..'
alias up4='cd ../../../..'
alias n='nano'
g() {
geany $1 &
}
alias e='exit'
alias bye='exit'
alias s='sudo -i'
mcd() {
mkdir -p $1
cd $1
}
link-file() {
if [[ -n "$1" && -n "$2" && -f "$1" && ! -f "$2" ]]; then
ln -s "$1" "$2"
else
echo "link /home/user/source_FILE /opt/new_link"
fi
}
link-dir() {
if [[ -n "$1" && -n "$2" && -d "$1" && ! -f "$2" ]]; then
ln -s "$1" "$2"
else
echo "link /home/user/source_DIR /opt/new_link"
fi
}
alias findblanks='sudo awk -F: '\''($2 == "") {print}'\'' /etc/shadow'
alias findrootusers='sudo awk -F: '\''($3 == "0") {print}'\'' /etc/passwd'
alias lock='gnome-screensaver-command --lock'
alias mounted='mount | column -t'
alias md='mkdir -p'
alias o='less'
# wget -c will resume getting a partially-downloaded file.
alias wget='wget -c'
#Maintance
alias cleantmp='find /tmp -atime +3 -exec rm -f {} ";"'
#Web
alias chrome='/opt/google/chrome/chrome'
#my default browser
alias web=chrome
#CPU and Memory useage
# pass options to free
alias meminfo='free -m -l -t'
#File Useage
# Disks and File System useage
alias df='df -H'
# Disk Usage for a folder in useful sizes
alias du='du -ch'
alias disks=df
alias useage=du
alias home='echo "Please wait... Calculating Size of Home..." && du -s /home'
# get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
# get top process eating cpu
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
# Get server cpu info
alias cpuinfo='lscpu'
#Debug Web Server
alias errors=ap_errors
alias ap_errors='tail /var/log/apache2/error.log'
alias hh_errors='tail /var/log/hhvm/error.log'
alias ng_errors='tail /var/log/nginx/error.log'
# Get web server headers #
alias header='curl -I'
# Find out if remote server supports gzip / mod_deflate or not #
alias headerc='curl -I --compress'
# Controll Web Servers
alias a2='sudo service apache2 restart'
alias hh_restart='sudo service hhvm restart'
alias t7='sudo /etc/init.d/tomcat7 restart'
alias phpstatus='service php5-fpm status'
alias phpstart='service php5-fpm start'
alias ngreload='sudo /usr/sbin/nginx -s reload'
alias ngtest='sudo /usr/sbin/nginx -t'
alias lightyload='sudo /etc/init.d/lighttpd reload'
alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t'
alias httpdreload='sudo /usr/sbin/apachectl -k graceful'
alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS'
#Windows to linux
alias attrib='chmod'
alias chdir='cd'
alias copy='cp'
alias del='rm'
alias deltree='rm -r'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias edit='nano'
alias ff='whereis'
alias mem='top'
alias move='mv'
## You should use these on servers instead of default commands...!!
#set nice levels for common commands
alias ncfg='nice -n 2 ./configure'
alias nmake='nice -n 2 make'
alias nmakeinstall='sudo nice -n 2 make install'
alias ncp='nice -n 17 cp -iv'
alias nmv='nice -n 17 mv -iv'
alias nrm='nice -n 17 rm -I --preserve-root'
alias ncurl='nice -n 17 curl'
nmaketar() {
if [ -e "$1" ]; then
nice -n 17 tar cvzf "$1.tgz" "$@"
else
if [ -e "$2" ]; then
x=""
for var in "$@"
do
if [ -e "$var" ]; then
x+=$var
x+=" "
fi
done
nice -n 17 tar cvzf "$1.tgz" $x
else
if [ -n "$1" ]; then
nice -n 17 tar cvzf "$1.tgz" *
else
nice -n 17 tar cvzf all.tgz *
fi
fi
fi
}
alias ntar='nice -n 17 tar'
alias nungz='nice -n 17 tar xvfz'
alias nuntar='nice -n 17 tar xvf'
alias nl='nice -n 17 ls --color=auto -alh'
alias nn='nice -n 17 nano'
ng() {
nice -n 17 geany $1 &
}
alias no='nice -n 17 less'
alias nless='nice -n 17 less'
alias ngrep='nice -n 17 grep --color=auto'
alias nhg='history | nice -n 17 grep --color=auto'
#RSYNC
alias nbackup="nice -n 2 rsync --progress -ravz"
alias nrsync="nice -n 2 rsync"
#apt-get
alias nagi='sudo nice -n 2 apt-get install'
alias nagr='sudo nice -n 2 apt-get remove'
alias nagu='sudo nice -n 2 apt-get update'
alias nacs='nice -n 2 apt-cache search'
#git
alias ngs='nice -n 17 git status'
alias ngc='nice -n 17 git commit -a -m'
alias nmpull='nice -n 17 git pull origin master'
alias nmpush='nice -n 17 git push origin master'
alias npull='nice -n 17 git pull origin'
alias npush='nice -n 17 git push origin'
alias ngb='nice -n 17 git branch'
alias nbranch='nice -n 17 git branch'
alias nclone='nice -n 17 git clone'
alias ncheckout='nice -n 17 git checkout'
# useage up 3 cd ../../..
up(){
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
}
I work with PHP 7.3. Linux OS: Ubuntu 18.04. IDE: Apache NetBeans 10. DB: MySQL.
Tuesday, September 19, 2017
.bash_aliases - Common Lazy Admin Stuff
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment