### Get os name via uname ###_myos="$(uname)"### add alias as per os using $_myos ###case$_myos in
Linux)alias foo='/path/to/linux/bin/foo';;
FreeBSD|OpenBSD)alias foo='/path/to/bsd/bin/foo' ;;
SunOS)alias foo='/path/to/sunos/bin/foo' ;;
*) ;;
esac
30个有用的别名
你可以定义不同类型的别名来节约时间和提升效率。
#1: 控制ls命令输出
给ls命令的输出来电颜色看看
12345678
## Colorize the ls output ##alias ls='ls --color=auto'## Use a long listing format ##alias ll='ls -la'## Show hidden files ##alias l.='ls -d .* --color=auto'
#2: 调整cd命令习惯
12345678910
## get rid of command not found ##alias cd..='cd ..'## a quick way to get out of current directory ##alias ..='cd ..'alias ...='cd ../../../'alias ....='cd ../../../../'alias .....='cd ../../../../'alias .4='cd ../../../../'alias .5='cd ../../../../..'
#3:控制grep命令输出
1234
## Colorize the grep command output for ease of use (good for log files)##alias grep='grep --color=auto'alias egrep='egrep --color=auto'alias fgrep='fgrep --color=auto'
## replace mac with your actual server mac address #alias wakeupnas01='/usr/bin/wakeonlan 00:11:32:11:15:FC'alias wakeupnas02='/usr/bin/wakeonlan 00:11:32:11:15:FD'alias wakeupnas03='/usr/bin/wakeonlan 00:11:32:11:15:FE'
#15:控制防火墙(iptables)输出
123456789
## shortcut for iptables and pass it via sudo#alias ipt='sudo /sbin/iptables'# display all 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
#16:通过curl调试web服务或者CDN问题
12345
# get web server headers #alias header='curl -I'# find out if remote server supports gzip / mod_deflate or not #alias headerc='curl -I --compress'
#17:一些安全的设置
123456789101112
# do not delete / or prompt if deleting more than 3 files at a time #alias rm='rm -I --preserve-root'# confirmation #alias mv='mv -i'alias cp='cp -i'alias ln='ln -i'# Parenting changing perms on / #alias chown='chown --preserve-root'alias chmod='chmod --preserve-root'alias chgrp='chgrp --preserve-root'
# also pass it via sudo so whoever is admin can reload it without calling you #alias nginxreload='sudo /usr/local/nginx/sbin/nginx -s reload'alias nginxtest='sudo /usr/local/nginx/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'
#22:给备份做别名
1234567891011
# if cron fails or if you want backup on demand just run these commands # # again pass it via sudo so whoever is in admin group can start the job ## Backup scripts #alias backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type local --taget /raid1/backups'alias nasbackup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01'alias s3backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01 --auth /home/scripts/admin/.authdata/amazon.keys'alias rsnapshothourly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'alias rsnapshotdaily='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'alias rsnapshotweekly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'alias rsnapshotmonthly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'alias amazonbackup=s3backup
#23:系统管理员设置端口相关的命令
12345678910
## All of our servers eth1 is connected to the Internets via vlan / router etc ##alias dnstop='dnstop -l 5 eth1'alias vnstat='vnstat -i eth1'alias iftop='iftop -i eth1'alias tcpdump='tcpdump -i eth1'alias ethtool='ethtool eth1'# work on wlan0 by default ## Only useful for laptop as all servers are without wireless interfacealias iwconfig='iwconfig wlan0'
#24:快速获取系统内存、cpu使用以及gpu内存信息
12345678910111213141516171819
## pass options to free ## alias meminfo='free -m -l -t'## get top process eating memoryalias 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'## older system use /proc/cpuinfo ####alias cpuinfo='less /proc/cpuinfo' #### get GPU ram on desktop / laptop## alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'
#25:控制家庭路由器
12345
# Reboot my home Linksys WAG160N / WAG54 / WAG320 / WAG120N Router / Gateway from *nix.alias rebootlinksys="curl -u 'admin:my-super-password' 'http://192.168.1.2/setup.cgi?todo=reboot'"# Reboot tomato based Asus NT16 wireless bridge alias reboottomato="ssh admin@192.168.1.1 /sbin/reboot"
#26:wget续传
12
## this one saved by butt so many times ##alias wget='wget -c'
#27:使用不同的浏览器测试网页
1234567891011
## this one saved by butt so many times ##alias ff4='/opt/firefox4/firefox'alias ff13='/opt/firefox13/firefox'alias chrome='/opt/google/chrome/chrome'alias opera='/opt/opera/opera'#default ff alias ff=ff13
#my default browser alias browser=chrome
#28:ssh小贴士
不创建别名,通过使用OpenSSH配置文件~/.ssh/config配置,它提供了很多选项,如:
1234567
Host server10
Hostname 1.2.3.4
IdentityFile ~/backups/.ssh/id_dsa
user foobar
Port 30000
ForwardX11Trusted yes
TCPKeepAlive yes
现在可以通过如下命令连接
1
$ ssh server10
#29:现在轮到你分享了
12345678910111213141516171819202122232425
## set some other defaults ##alias df='df -H'alias du='du -ch'# top is atop, just like vi is vimalias top='atop'## nfsrestart - must be root #### refresh nfs mount / cache etc for Apache ##alias nfsrestart='sync && sleep 2 && /etc/init.d/httpd stop && umount netapp2:/exports/http && sleep 2 && mount -o rw,sync,rsize=32768,wsize=32768,intr,hard,proto=tcp,fsc natapp2:/exports /http/var/www/html && /etc/init.d/httpd start'## Memcached server status ##alias mcdstats='/usr/bin/memcached-tool 10.10.27.11:11211 stats'alias mcdshow='/usr/bin/memcached-tool 10.10.27.11:11211 display'## quickly flush out memcached server ##alias flushmcd='echo "flush_all" | nc 10.10.27.11 11211'## Remove assets quickly from Akamai / Amazon cdn ##alias cdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai'alias amzcdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon'## supply list of urls via file or stdinalias cdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai --stdin'alias amzcdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon --stdin'