原文来自 http://blog.jobbole.com/84755/
提升生产力
这些别名真的很简单并且真的很短,但他们大多数是为了给你的生命节省几秒钟,最终也许为你这一辈子节省出来几年,也许呢。
1
|
alias ls= "ls --color=auto"
|
简单但非常重要。使ls命令带着彩色输出。
1
|
alias ll= "ls --color -al"
|
以彩色的列表方式列出目录里面的全部文件。
1
|
alias grep= 'grep --color=auto'
|
类似,只是在grep里输出带上颜色。
1
|
mcd() { mkdir -p "$1" ; cd "$1" ;}
|
我的最爱之一。创建一个目录并进入该目录里: mcd [目录名]。
1
|
cls() { cd "$1" ; ls;}
|
类似上一个函数,进入一个目录并列出它的的内容:cls[目录名]。
1
|
backup() { cp "$1" {,.bak};}
|
简单的给文件创建一个备份: backup [文件] 将会在同一个目录下创建 [文件].bak。
1
|
md5check() { md5sum "$1" | grep "$2" ;}
|
因为我讨厌通过手工比较文件的md5校验值,这个函数会计算它并进行比较:md5check[文件][校验值]。
1
|
alias makescript= "fc -rnl | head -1 >"
|
很容易用你上一个运行的命令创建一个脚本:makescript [脚本名字.sh]
1
|
alias genpasswd= "strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo"
|
只是瞬间产生一个强壮的密码。
1
|
alias c= "clear"
|
清除你终端屏幕不能更简单了吧?
1
|
alias histg= "history | grep"
|
快速搜索你的命令输入历史:histg [关键字]
1
|
alias ..= 'cd ..'
|
回到上层目录还需要输入 cd 吗?
1
|
alias ...= 'cd ../..'
|
自然,去到上两层目录。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
extract() { if [ -f $ 1 ] ; then
case $ 1 in
*.tar.bz2) tar xjf $ 1 ;;
*.tar.gz) tar xzf $ 1 ;;
*.bz2) bunzip2 $ 1 ;;
*.rar) unrar e $ 1 ;;
*.gz) gunzip $ 1 ;;
*.tar) tar xf $ 1 ;;
*.tbz2) tar xjf $ 1 ;;
*.tgz) tar xzf $ 1 ;;
*.zip) unzip $ 1 ;;
*.Z) uncompress $ 1 ;;
*.7z) 7z x $ 1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
} |
很长,但是也是最有用的。解压任何的文档类型:extract: [压缩文件]
系统信息
想尽快地知道关于你的系统一切信息?
1
|
alias cmount= "mount | column -t"
|
按列格式化输出mount信息。
1
|
alias tree= "ls -R | grep " :$ " | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"
|
以树形结构递归地显示目录结构。
1
|
sbs() { du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e' ;}
|
安装文件在磁盘存储的大小排序,显示当前目录的文件列表。
1
|
alias intercept= "sudo strace -ff -e trace=write -e write=1,2 -p"
|
接管某个进程的标准输出和标准错误。注意你需要安装了 strace。
1
|
alias meminfo= 'free -m -l -t'
|
查看你还有剩下多少内存。
1
|
alias ps? = "ps aux | grep"
|
可以很容易地找到某个进程的PID:ps? [名字]。
1
|
alias volume= "amixer get Master | sed '1,4 d' | cut -d [ -f 2 | cut -d ] -f 1"
|
显示当前音量设置。
网络
对于所有用在互联网和本地网络的命令,也有一些神奇的别名给它们。
1
|
alias websiteget= "wget --random-wait -r -p -e robots=off -U mozilla"
|
下载整个网站:websiteget [URL]。
1
|
alias listen= "lsof -P -i -n"
|
显示出哪个应用程序连接到网络。
1
|
alias port= 'netstat -tulanp'
|
显示出活动的端口。
1
|
gmail() { curl -u "$1" --silent "https://mail.google.com/mail/feed/atom" | sed -e 's/<\/fullcount.*/\n/' | sed -e 's/.*fullcount>//' }
|
大概的显示你的谷歌邮件里未读邮件的数量:gmail [用户名]
1
|
alias ipinfo= "curl ifconfig.me && curl ifconfig.me/host"
|
获得你的公网IP地址和主机名。
1
|
getlocation() { lynx -dump http: //www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\';}
|
返回你的当前IP地址的地理位置。
也许无用
所以呢,如果一些别名并不是全都具有使用价值?它们可能仍然有趣。
1
|
kernelgraph() { lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -;}
|
绘制内核模块依赖曲线图。需要可以查看图片。
1
|
alias busy= "cat /dev/urandom | hexdump -C | grep 'ca fe'"
|
在那些非技术人员的眼里你看起来是总是那么忙和神秘。
最后,这些别名和函数的很大一部分来自于我个人的.bashrc。而那些令人点赞的网站 alias.sh和commandlinefu.com我早已在我的帖子best online tools for Linux 里面介绍过。你可以去看看,如果你愿意,也可以分享下你的。也欢迎你在这里评论,分享一下你的智慧。
做为奖励,这里有我提到的全部别名和函数的纯文本版本,随时可以复制粘贴到你的.bashrc。(如果你已经一行一行的复制到这里了,哈哈,你发现你又浪费了生命的几秒钟~)
#Productivity alias ls="ls --color=auto" alias ll="ls --color -al" alias grep='grep --color=auto' mcd() { mkdir -p "$1"; cd "$1";} cls() { cd "$1"; ls;} backup() { cp "$1"{,.bak};} md5check() { md5sum "$1" | grep "$2";} alias makescript="fc -rnl | head -1 >" alias genpasswd="strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo" alias c="clear" alias histg="history | grep" alias ..='cd ..' alias ...='cd ../..' extract() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar e $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via extract()" ;; esac else echo "'$1' is not a valid file" fi } #System info alias cmount="mount | column -t" alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'" sbs(){ du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e';} alias intercept="sudo strace -ff -e trace=write -e write=1,2 -p" alias meminfo='free -m -l -t' alias ps?="ps aux | grep" alias volume="amixer get Master | sed '1,4 d' | cut -d [ -f 2 | cut -d ] -f 1" #Network alias websiteget="wget --random-wait -r -p -e robots=off -U mozilla" alias listen="lsof -P -i -n" alias port='netstat -tulanp' gmail() { curl -u "$1" --silent "https://mail.google.com/mail/feed/atom" | sed -e 's/<\/fullcount.*/\n/' | sed -e 's/.*fullcount>//'} alias ipinfo="curl ifconfig.me && curl ifconfig.me/host" getlocation() { lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\';} #Funny kernelgraph() { lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -;} alias busy="cat /dev/urandom | hexdump -C | grep \"ca fe\""
相关推荐
bash-lambda, bash的匿名函数和FP内容 Bash注意:由于性能原因,由于切换到 zsh,我不再积极维护这个项目。 我可以能会编写类似于wince的类似的内容,但是很希望自动散列支持更快。对 bash ( 一个功能完备的黑客)的...
gam是一个CLI工具,用于永久创建,更新和删除bash别名
bash写的字符串常用函数,这个可以看看。资源分就免了
dotfiles -我的Bash函数/命令/别名 dotfiles是所有bash函数/命令/别名都应驻留的特殊位置。 您所需要做的就是运行安装脚本,并且~/.dotfiles文件夹中的自定义脚本已准备好在终端中使用! 添加您的自定义Bash函数 将...
gittify - 一个多彩的Bash提示符 自定义的Git别名
kube-aliases:Kubernetes别名和Bash函数
有多少次您在命令行上多次输入一个长命令,并希望有一种方法将其保存到以后?这就是Bash别名派上用场的地方。它们允许您将长而神秘的命令浓缩成易于记忆和使用的命令。需要一些例子让你开始吗?没问题! 要使用您创建...
自己写的几个Bash脚本 适用系统:CentOS6.x CentOS7.x 上传到CentOS系统中任意目录解压 #tar -xvf ./BashScripts.tar.gz ./bin/目录为脚本存放目录,包括配置host文件,关闭防火墙,改为静态NAT连接,卸载系统自带jdk并...
bash-utility:Bash库,为Bash中的函数编程提供实用程序功能和帮助程序
linux-Utilitybashscripts使用单个命令执行可自动执行任务的实用bash脚本
bash-fun: bash中的函数式编程
awesome-bash-alias:精选的Bash别名别名列表
gitbash和sourceTree
您是否为 Bash shell 中大量的测试和比较选项而困惑呢?这个技巧可以帮助您解密不同类型的文件、算术和字符串测试,这样您就能够知道什么时候使用 test、 [ ]、 [[ ]]、 (( )) 或 if-then-else 了。本文介绍了如何...
Bash风格指南:规范、最佳实践和实用技巧
AnyBar 图标日志一组 Bash 函数和别名,可以从命令行使用 AnyBar 作为个人日志。 设计用于使用自定义图标。先决条件安装克隆 repo,然后在.bashrc文件中获取脚本。 例如,如果您将 repo 克隆到您的HOME目录: . "$...
bash_aliases:一个收集有用的bash别名的项目
主要介绍了一波实用的Bash Shell整理,适用于Ubuntu等Debian系的Linux系统,需要的朋友可以参考下
bash 编程bash 编程bash 编程bash 编程bash 编程bash 编程bash 编程bash 编程bash 编程bash 编程
具有vim和纯净别名的bash配置 别名是指可以使用不同名称访问相同存储位置的情况。 例如: 之前: cd /home/user 创建别名: alias home='cd /home/user' 之后: home 平台类 macOS和Linux 安装 运行curl ...