### 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
## Colorize the ls output ## aliasls = 'ls--color=auto'
## Use a long listing format ## alias ll = 'ls -la'
## Show hidden files ## alias l.= 'ls -d . ...git.gitignore.gitmodules.travis.yml--color=auto'
#2:控制 cd 命令的行为
1 2 3 4 5 6 7 8 9 10 11
## get rid of command not found ## aliascd..= 'cd..'
## a quick way to get out of current directory ## alias..= 'cd..' alias...= 'cd../../../' alias....= 'cd../../../../' alias.....= 'cd../../../../' alias.4= 'cd../../../../' alias.5= 'cd../../../../..'
## Colorize the grep command output for ease ofuse (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'
# reboot / halt / poweroff alias reboot = 'sudo /sbin/reboot' alias poweroff = 'sudo /sbin/poweroff' alias halt = 'sudo /sbin/halt' aliasshutdown = 'sudo /sbin/shutdown'
#21:控制 web 服务器
1 2 3 4 5 6 7 8
# 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/lighttpdreload' 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:与备份相关的别名
1 2 3 4 5 6 7 8 9 10 11 12
# 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:桌面应用相关的别名 - 按需播放的 avi/mp3 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
## play video files in a current directory ## # cd ~/Download/movie-name # playavi or vlc alias playavi = 'mplayer *.avi' alias vlc = 'vlc *.avi'
# play all music files from the current directory # alias playwave = 'for i in *.wav; do mplayer "$i"; done' alias playogg = 'for i in *.ogg; do mplayer "$i"; done' alias playmp3 = 'for i in *.mp3; do mplayer "$i"; done'
# play files from nas devices # alias nplaywave = 'for i in /nas/multimedia/wave/*.wav; do mplayer "$i"; done' alias nplayogg = 'for i in /nas/multimedia/ogg/*.ogg; do mplayer "$i"; done' alias nplaymp3 = 'for i in /nas/multimedia/mp3/*.mp3; do mplayer "$i"; done'
# shuffle mp3/ogg etc by default # alias music = 'mplayer --shuffle *'
## this one saved by butt so many times ## alias wget = 'wget -c'
#28:使用不同浏览器来测试网站
1 2 3 4 5 6 7 8 9 10 11 12
## 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'
## set some other defaults ## alias df = 'df -H' alias du = 'du -ch'
# top is atop, just like vi is vim alias 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 stdin alias cdnmdel = '/home/scripts/admin/cdn/purge_cdn_cache--profile akamai --stdin' alias amzcdnmdel = '/home/scripts/admin/cdn/purge_cdn_cache--profile amazon --stdin'
总结
本文总结了 *nix bash 别名的多种用法:
为命令设置默认的参数(例如通过 alias ethtool='ethtool eth0' 设置 ethtool 命令的默认参数为 eth0)。