Reprinted: linux alias Tips

Since the 10 command aliases know me very happy, because if I had known, I would not be titanium keyboard poke bad!

 

Alias ​​is what?

Alias ​​is a nickname, or call shorthand, such as if you African brothers "exaggerated boast a long cucumber scrape it does not boast palm Cameroon fried fried rotten," shouted the name of children is too long not agile, you can give him alias "non-Arab" or " Akwa ', the next time a child African brothers know you called him!

 

Odd kinky tricks

Most people define aliases are defined as:

alias n='echo HelloWorld' 

Today I teach you a more defined method 6, to ensure that the level of 6, 6 Style:

alias n='f(){ echo $1; }; f'

This corresponds to the definition of a function f, and call it the end, see "$ 1" yet? Alias ​​defined in this way can pass parameters! Old iron that show, ah bah, not 6 6?

List all files

ll command must have the highest frequency of use of Linux, the default is actually ll command ls -l --color = auto alias, the system default, there's no need to define your own, but it is not easy to use, we recommend a custom reason : convenience, ll and la is the use of relatively high frequency recommendation: Five star

alias ll='ls -lht' #按修改时间逆序列出文件
alias la='ls -lhta' #按修改时间逆序列出所有文件
# 调用示例
ll /usr  # ls本身后面就可以跟路径参数

 

Check the file / directory size

Disk space is full when you want to find large files this command is simply an artifact! Recommended reason: to view files quickly occupied size, easy to modify the path, the current default directory Recommendation: Five Star

alias size='f(){ du -sh $1* | sort -hr; }; f'
# 调用示例
size   #当前目录
size / #根目录

 

Demo:

 

Find Files

Recommended reason: Sometimes a file transfer to Linux, but do not know where documents are going to run this command is especially useful! Recommendation: Five Star

alias sek='f(){ find / -name $1; }; f' # 在根目录查找文件
# 调用示例 
sek myfile

 

Brothers alias, find the file in the current directory

alias sekc='f(){ find ./ -name $1; }; f'
# 调用示例
sekc myfile

 

Open port

When you want to open a port and do not want to check tedious iptables command, alias is very useful Recommended reason: fast open ports, do not inquire complicated iptables command, you must pass the port number Recommendation: Five Star

alias portopen='f(){ /sbin/iptables -I INPUT -p tcp --dport $1 -j ACCEPT; }; f'
# 调用示例 
portopen 8080

 

Brothers aliases, quick closing ports

alias portclose='f(){ /sbin/iptables -I INPUT -p tcp --dport $1 -j DROP; }; f'
# 调用示例 
portclose 8080

 

Temporary open HTTP service

Recommended reason: this is simply an artifact when you need to download files in a directory or html quick access when you need it! If you can not access needed to see whether the port is open! Recommendation: Five Star

alias www='f(){ python -m SimpleHTTPServer $1; }; f'
# 调用示例:
www       #不传端口,默认8000
www 8080 #8080端口开启HTTP服务

 

Demo:

 

Check boot entry

Recommended reason: nothing to say, this order is too long, it gave him a name it is called auto Recommendation: Five Star

alias auto='systemctl list-unit-files --type=service | grep enabled | more'
# 调用示例
auto
# 回显如下
[email protected]                               enabled 
chronyd.service                               enabled 
crond.service                                 enabled 
[email protected]                                enabled 
iptables.service                              enabled 
--More--

 

View the current time

Recommended reason: By default all know that time is a date to view the Linux command, which returns the time format looked like to beat: Sat Dec 22 03:57:08 UTC 2018, nothing to say, named after formatting now Recommended for children : Five star

alias now='date "+%Y-%m-%d %H:%M:%S"'
# 调用示例
now
# 回显如下
2018-12-22 03:59:33

View Docker mirroring details

推荐理由:有时候想看哪个docker镜像流量用的最多,docker stats命令一个一个去对比真是很蛋疼,所以有了它,你也可以按照另外的字段排序,修改-k8中的8为另外的数字,这个数字表示按照哪个字段排序 推荐指数:五星

alias dkrnet='docker stats --no-stream | sort -k8 -hr | more'
# 调用示例
dkrnet
# 回显如下
f27760776941        ccc1                0.04% 49MiB / 985.3MiB 4.97% 41.2GB / 47.5GB 156GB / 14MB 14
783353fc3522        ccc2                0.00% 5.941MiB / 985.3MiB 0.60% 14.4GB / 14.7GB 7.37GB / 0B 1
e35fcbb46b7e        ccc3                0.00% 4.676MiB / 985.3MiB 0.47% 1.63GB / 1.6GB 3.04GB / 0B 1
--More--

 

解压

推荐理由:用过zip命令的都知道它有一个兄弟叫unzip,可是tar和jar没有,每次解压都不知道后面参数该怎么跟,所以给它取名儿untar或者unjar 推荐指数:四星

alias untar='tar xvf '
alias unjar='jar xvf '
# 调用示例
untar a.tar.gz
unjar java.jar

 

查看外网IP

推荐理由:想查看自己的外网IP?没问题! 推荐指数:五星

alias ipe='curl ipinfo.io/ip' 

写在最后

别名的正确使用方式是将别名写入~/.bashrc文件里面,保证下次登录还能使用,我将上面的别名来了一个汇总,老铁按需自取!

vi ~/.bashrc
# 将以下别名写出文件并退出
alias ll='ls -lht' #按修改时间逆序列出文件
alias la='ls -lhta' #按修改时间逆序列出所有文件
alias size='f(){ du -sh $1* | sort -hr; }; f'
alias sek='f(){ find / -name $1; }; f' # 在根目录查找文件
alias sekc='f(){ find ./ -name $1; }; f'
alias portopen='f(){ /sbin/iptables -I INPUT -p tcp --dport $1 -j ACCEPT; }; f'
alias portclose='f(){ /sbin/iptables -I INPUT -p tcp --dport $1 -j DROP; }; f'
alias www='f(){ python -m SimpleHTTPServer $1; }; f'
alias auto='systemctl list-unit-files --type=service | grep enabled | more'
alias now='date "+%Y-%m-%d %H:%M:%S"'
alias dkrnet='docker stats --no-stream | sort -k8 -hr | more'
alias untar='tar xvf '
alias unjar='jar xvf '
alias ipe='curl ipinfo.io/ip' 

# 最后别忘了执行以下命令使别名生效
source ~/.bashrc

Guess you like

Origin www.cnblogs.com/Geralt-of-Rivia/p/11318523.html