#有的系统不支持ll命令,即查看列表的方式。
alias ll='ls -lh'#显示隐藏文件
alias lla='ls -lha'#开启一个以当前目录为webroot的HTTP服务,非常好用,用于文件分析
alias www='python -m SimpleHTTPServer 8000'#查看外部IP
alias ipe='curl ipinfo.io/ip'#查看本机IP
alias ipi='ipconfig getifaddr en0'#生成一个20位长度的随机密码
alias getpass="openssl rand -base64 20"#方便打印路径信息列表
alias path='echo -e ${PATH//:/\\n}'#打印当前时间
alias now='date "+%Y-%m-%d %H:%M:%S"'
alias nowtime=now#打印当前日期
alias nowdate='date +"%Y-%m-%d"'#打印时间戳
alias timestamp='date "+%Y%m%d%H%M%S"'

参考地址:

https://opensource.com/article/18/9/handy-bash-aliases

https://linuxtoy.org/archives/10-bash-alias.html

关于系统别名的一些操作和限制的参考:

https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html

10 handy Bash aliases for Linux

Get more efficient by using condensed versions of long Bash commands.

How many times have you repeatedly typed out a long command on the command line and wished there was a way to save it for later? This is where Bash aliases come in handy. They allow you to condense long, cryptic commands down to something easy to remember and use. Need some examples to get you started? No problem!

To use a Bash alias you've created, you need to add it to your .bash_profile file, which is located in your home folder. Note that this file is hidden and accessible only from the command line. The easiest way to work with this file is to use something like Vi or Nano.

10 handy Bash aliases

  1. How many times have you needed to unpack a .tar file and couldn't remember the exact arguments needed? Aliases to the rescue! Just add the following to your .bash_profile file and then use untar FileName to unpack any .tar file.
alias untar='tar -zxvf '
  1. Want to download something but be able to resume if something goes wrong?
alias wget='wget -c '
  1. Need to generate a random, 20-character password for a new online account? No problem.
alias getpass="openssl rand -base64 20"
  1. Downloaded a file and need to test the checksum? We've got that covered too.
alias sha='shasum -a 256 '
  1. A normal ping will go on forever. We don't want that. Instead, let's limit that to just five pings.
alias ping='ping -c 5'
  1. Start a web server in any folder you'd like.
alias www='python -m SimpleHTTPServer 8000'
  1. Want to know how fast your network is? Just download Speedtest-cli and use this alias. You can choose a server closer to your location by using the speedtest-cli --list command.
alias speed='speedtest-cli --server 2406 --simple'
  1. How many times have you needed to know your external IP address and had no idea how to get that info? Yeah, me too.
alias ipe='curl ipinfo.io/ip'
  1. Need to know your local IP address?
alias ipi='ipconfig getifaddr en0'
  1. Finally, let's clear the screen.
alias c='clear'

As you can see, Bash aliases are a super-easy way to simplify your life on the command line. Want more info? I recommend a quick Google search for "Bash aliases" or a trip to GitHub.

SimpleHTTPServer:

https://docs.python.org/2/library/simplehttpserver.html

参考地址: https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html

30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X

More about bash alias

The general syntax for the alias command for the bash shell is as follows:

How to list bash aliases

Type the following alias command:
alias
Sample outputs:

alias ..='cd ..'
alias amazonbackup='s3backup'
alias apt-get='sudo apt-get'
...

By default alias command shows a list of aliases that are defined for the current user.

How to define or create a bash shell alias

To create the alias use the following syntax:

alias name=value
alias name='command'
alias name='command arg1 arg2'
alias name='/path/to/script'
alias name='/path/to/script.pl arg1'

In this example, create the alias c for the commonly used clear command, which clears the screen, by typing the following command and then pressing the ENTER key:

alias c='clear'

Then, to clear the screen, instead of typing clear, you would only have to type the letter ‘c’ and press the [ENTER] key:

c

How to disable a bash alias temporarily

An alias can be disabled temporarily using the following syntax:

## path/to/full/command
/usr/bin/clear
## call alias with a backslash ##
\c
## use /bin/ls command and avoid ls alias ##
command ls

How to delete/remove a bash alias

You need to use the command called unalias to remove aliases. Its syntax is as follows:

unalias aliasname
unalias foo

In this example, remove the alias c which was created in an earlier example:

unalias c

You also need to delete the alias from the ~/.bashrc file using a text editor (see next section).

How to make bash shell aliases permanent

The alias c remains in effect only during the current login session. Once you logs out or reboot the system the alias c will be gone. To avoid this problem, add alias to your ~/.bashrc file, enter:

vi ~/.bashrc

The alias c for the current user can be made permanent by entering the following line:

alias c='clear'

Save and close the file. System-wide aliases (i.e. aliases for all users) can be put in the /etc/bashrc file. Please note that the alias command is built into a various shells including ksh, tcsh/csh, ash, bash and others.

A note about privileged access

You can add code as follows in ~/.bashrc:

# if user is not root, pass all commands via sudo #
if [ $UID -ne 0 ]; thenalias reboot='sudo reboot'alias update='sudo apt-get upgrade'
fi

A note about os specific aliases

You can add code as follows in ~/.bashrc using the case statement:

### Get os name via uname ###
_myos="$(uname)"### add alias as per os using $_myos ###
case $_myos inLinux) 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 bash shell aliases examples

You can define various types aliases as follows to save time and increase productivity.

#1: Control ls command output

The ls command lists directory contents and you can colorize the output:

## 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: Control cd command behavior

## 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: Control grep command output

grep command is a command-line utility for searching plain-text files for lines matching a regular expression:

## 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'

#4: Start calculator with math support

alias bc='bc -l'

#4: Generate sha1 digest

alias sha1='openssl sha1'

#5: Create parent directories on demand

mkdir command is used to create a directory:

alias mkdir='mkdir -pv'

#6: Colorize diff output

You can compare files line by line using diff and use a tool called colordiff to colorize diff output:

# install  colordiff package :)
alias diff='colordiff'

#7: Make mount command output pretty and human readable format

alias mount='mount |column -t'

#8: Command short cuts to save time

# handy short cuts #
alias h='history'
alias j='jobs -l'

#9: Create a new set of commands

alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowtime=now
alias nowdate='date +"%d-%m-%Y"'

#10: Set vim as default

alias vi=vim
alias svi='sudo vi'
alias vis='vim "+set si"'
alias edit='vim'

#11: Control output of networking tool called ping

# Stop after sending count ECHO_REQUEST packets #
alias ping='ping -c 5'
# Do not wait interval 1 second, go fast #
alias fastping='ping -c 100 -s.2'

#12: Show open ports

Use netstat command to quickly list all TCP/UDP port on the server:

alias ports='netstat -tulanp'

#13: Wakeup sleeping servers

Wake-on-LAN (WOL) is an Ethernet networking standard that allows a server to be turned on by a network message. You can quickly wakeup nas devices and server using the following aliases:

## 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'

#14: Control firewall (iptables) output

Netfilter is a host-based firewall for Linux operating systems. It is included as part of the Linux distribution and it is activated by default. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.

## 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

#15: Debug web server / cdn problems with curl

# get web server headers #
alias header='curl -I'# find out if remote server supports gzip / mod_deflate or not #
alias headerc='curl -I --compress'

#16: Add safety nets

# 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'

#17: Update Debian Linux server

apt-get command is used for installing packages over the internet (ftp or http). You can also upgrade all packages in a single operations:

# distro specific  - Debian / Ubuntu and friends #
# install with apt-get
alias apt-get="sudo apt-get"
alias updatey="sudo apt-get --yes"# update on one command
alias update='sudo apt-get update && sudo apt-get upgrade'

#18: Update RHEL / CentOS / Fedora Linux server

yum command is a package management tool for RHEL / CentOS / Fedora Linux and friends:

## distrp specifc RHEL/CentOS ##
alias update='yum update'
alias updatey='yum -y update'

#19: Tune sudo and su

# become root #
alias root='sudo -i'
alias su='sudo -i'

#20: Pass halt/reboot via sudo

shutdown command bring the Linux / Unix system down:

# reboot / halt / poweroff
alias reboot='sudo /sbin/reboot'
alias poweroff='sudo /sbin/poweroff'
alias halt='sudo /sbin/halt'
alias shutdown='sudo /sbin/shutdown'

#21: Control web servers

# 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: Alias into our backup stuff

# 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: Desktop specific – play avi/mp3 files on demand

## 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 *'

#24: Set default interfaces for sys admin related commands

vnstat is console-based network traffic monitor. dnstop is console tool to analyze DNS traffic. tcptrack and iftop commands displays information about TCP/UDP connections it sees on a network interface and display bandwidth usage on an interface by host respectively.

## 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 interface
alias iwconfig='iwconfig wlan0'

#25: Get system memory, cpu usage, and gpu memory info quickly

## pass options to free ##
alias meminfo='free -m -l -t'## 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'## 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'

#26: Control Home Router

The curl command can be used to reboot Linksys routers.

# 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"

#27 Resume wget by default

The GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, and it can resume downloads too:

## this one saved by butt so many times ##
alias wget='wget -c'

#28 Use different browser for testing website

## 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

#29: A note about ssh alias

Do not create ssh alias, instead use ~/.ssh/config OpenSSH SSH client configuration files. It offers more option. An example:

Host server10Hostname 1.2.3.4IdentityFile ~/backups/.ssh/id_dsauser foobarPort 30000ForwardX11Trusted yesTCPKeepAlive yes

You can now connect to peer1 using the following syntax:
$ ssh server10

#30: It’s your turn to share…

## 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'

Conclusion

This post summarizes several types of uses for *nix bash aliases:

  1. Setting default options for a command (e.g. set eth0 as default option for ethtool command via alias ethtool='ethtool eth0' ).
  2. Correcting typos (cd.. will act as cd .. via alias cd..='cd ..').
  3. Reducing the amount of typing.
  4. Setting the default path of a command that exists in several versions on a system (e.g. GNU/grep is located at /usr/local/bin/grep and Unix grep is located at /bin/grep. To use GNU grep use alias grep='/usr/local/bin/grep' ).
  5. Adding the safety nets to Unix by making commands interactive by setting default options. (e.g. rm, mv, and other commands).
  6. Compatibility by creating commands for older operating systems such as MS-DOS or other Unix like operating systems (e.g. alias del=rm ).

I’ve shared my aliases that I used over the years to reduce the need for repetitive command line typing. If you know and use any other bash/ksh/csh aliases that can reduce typing, share below in the comments.

See also
  • Customize the bash shell environments
  • Download all aliases featured in this post
  • GNU bash shell home page

linux非常有用的别名相关推荐

  1. Linux系统之alias别名的基本使用

    Linux系统之alias别名的基本使用 一.alias别名介绍 1.alias简介 2.alias注意事项 二.检查本地系统环境 1.检查操作系统版本 2.检查系统内核版本 三.设置alias别名 ...

  2. 对中级 Linux 用户有用的 20 个命令

    也许你已经发现第一篇文章非常的有用,这篇文章是继对初级Linux用户非常有用的20个命令 的一个延伸. 第一篇文章的目的是为新手准备的而这篇文章则是为了Linux的中高级用户.在这里你将学会如何进行自 ...

  3. 对中级Linux用户有用的20个命令

    1. 命令: Find 搜索指定目录下的文件,从开始于父目录,然后搜索子目录. 注意: -name'选项是搜索大小写敏感.可以使用-iname'选项,这样在搜索中可以忽略大小写.(*是通配符,可以搜索 ...

  4. linux别名文件位置,Linux系统内置alias别名文件路径

    linux发行版本中centos就预设了很多方便的alias命令别名,这就是为什么很多人感觉centos系列使用上更加顺手的原因之一.linux的用户配置文件分为通用配置文件和用户个性化配置文件,分别 ...

  5. linux配置远程计算机别名没用,linux – `ssh foo“”`没有加载远程别名?

    摘要:为什么会失败 $ssh foo 'R --version | head -n 1' bash: R: command not found 但这成功了 $ssh foo 'grep -nHe 'b ...

  6. LINUX如何配置IP别名

    何谓ip别名? 用windows的话说,就是为一个网卡配置多个ip. 一.首先为服务器网卡配置静态ip地址 #ifconfig eth0 192.168.6.99 netmask 255.255.25 ...

  7. Linux之alias取别名

    温故: 上一篇文章和大家分享了kill命令的使用,尤其时"1""9""15"这三个信号一定要掌握,kill -9是平时大家用的比较多的,强制 ...

  8. linux给命令取别名,简化常用的linux命令

    在linux中很多时候我们会经常性的使用某些命令,比如切换到某个目录,但是目录结构太多,真的很累,这时候我们就可以自定义命令,也就是给命令取别名 1. 在当前用户的home目录下编辑 .bashrc  ...

  9. linux学习笔记-命令别名

    在使用linux批量查看文件或进行其他操作的时候,重复的输入部分较长命令比较浪费时间,为了提高效率,可以将命令重新取别名来简化操作. 命令别名指令alias,它的使用跟变量的定义规则相似,例: ali ...

最新文章

  1. js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource
  2. 【收藏】vue3+vite+ts 封装axios踩坑记录
  3. xhprof php性能分析工具
  4. 请设计一个栈,实现十进制数转任意进制数。
  5. 面试题:移动数组的元素
  6. 【ABP框架系列学习】N层架构(3)
  7. java获取达梦数据库_记一次对达梦数据库的优化过程
  8. Html5 学习系列(三)增强型表单标签
  9. Study 3 —— Python运算符
  10. 数据库防火墙数据库加密与脱敏数据泄露防护
  11. CSS的Border属性 属性 边框 可以 定义 宽度 颜色 CSS solid 类型 文本
  12. 将一个负数赋值给一个无符号数会出现什么情况呢
  13. 关于当前安全设置不允许下载文件问题的解决
  14. Android开机速度优化简单回顾——readahead
  15. Python常用的数据清洗方法
  16. 深入浅出的解释什么是tensor
  17. CVPR 2022 | 基于稀疏 Transformer 的单步三维目标识别器
  18. 南京理工大学matlab怎么弄,基于MATLAB/SimDriveline 的某型军用车辆 起步过程仿真研究...
  19. CSS3 @Media 媒体查询
  20. 商业模式创新与设计 -- 黄力泓

热门文章

  1. Java 面试必考题:动态代理
  2. 走近足球运动·与棒球相似的体育项目·第一堂棒球课
  3. python读取excel超链接
  4. 视口viewport的理解(布局视口、视觉视口、理想视口)
  5. VS Code配置C和Python调试环境,以及我自己的配置备份和参考
  6. Dubbo点对点直连配置详情
  7. php版本下载,Windows版本PHP下载-PHP For Windows下载v7.4.13 官方最新版-西西软件下载...
  8. CoreIDRAW平面设计总结
  9. 从本质看海明码——海明码的由来
  10. 刘晓燕英语语法句型学习总结4之状语从句