Some useful alias commands

Some useful alias commands

Linux and MaxOSX's alias command usage skills

Because the gist is more powerful, it has to be put in the repo.

alias

Note: There can be no spaces on both sides of the equal sign;

can be placed ~/.bash_profilein the file;

# SYS ALIAS
# ll显示隐藏文件
alias ll='ls -lAF'

# docker 快捷命令
alias dc='docker-compose'

# 查看Linux端口监听
alias port='netstat -ntlp'

# 查看MAC端口号监听
alias port='sudo lsof -iTCP -sTCP:LISTEN -n -P'

# 统计git仓库的代码行数
alias lines='git ls-files | xargs wc -l | grep total'

# MAC清理DNS缓存
alias dns='sudo killall -HUP mDNSResponder'


# set history format
export HISTTIMEFORMAT='%F %T  '
export HISTSIZE=10000
export HISTIGNORE='pwd:ls:ll:history:exit'

Or put it ~/.bashrcin , such as suor sudo suor sudo sudo suIt will take effect when switching the root user.

For specific effective rules, please refer to: Bash startup environment

If you have a useful alias, welcome to add: pr, wiki, comment are all fine.

shell

One shell command per day:

# 每日一个shell命令
cncounter:CODE_ALL renfufei$ type ls
ls is hashed (/bin/ls)
cncounter:CODE_ALL renfufei$ type ll
ll is aliased to 'ls -lAF'
cncounter:CODE_ALL renfufei$ type echo
echo is a shell builtin
cncounter:CODE_ALL renfufei$ type java
java is /Users/renfufei/.jenv/shims/java
cncounter:CODE_ALL renfufei$ which java
/Users/renfufei/.jenv/shims/java
cncounter:CODE_ALL renfufei$ whereis java
/usr/bin/java

Shell shortcut key (note that the default is not the shortcut key of vi/Vim, but the shortcut key of emacs):


- 清理屏幕`clear`: 使用 `Ctrl` + `l`
- 光标退回行首`ahead`: 使用 `Ctrl` + `a`
- 光标退回行尾`end`: 使用 `Ctrl` + `e`


- 从历史记录查找`research?`: `Ctrl + r` 进入, 然后输入模糊搜索字符串, 可再次使用 `Ctrl + r` 往前查找;

Vim快捷键:

- 光标退回行首: 在命令模式下输入数字 `0`
- 光标退回行尾: 在命令模式下输入数字 `$`

sudo password-free

Modify /etc/sudoersthe file to add the corresponding username and NOPASSWD:flag.

% sudo cat /etc/sudoers
#
# Sample /etc/sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.

##
# User specification
##

# root and users in group wheel can run anything on any machine as any user
#root		ALL = (ALL) ALL
#%admin		ALL = (ALL) ALL

# 免密SUDO, 改成类似这样的格式
root		ALL = (ALL) NOPASSWD:ALL
renfufei	ALL = (ALL) NOPASSWD:ALL
%admin		ALL = (ALL) NOPASSWD:ALL

After modification, use to :wq!save. Just re-enable the shell.

System tool installation

# 安装域名bind查询工具
yum -y install bind-utils

# 安装网络监控检测工具
yum -y install net-tools

# 安装系统状态监控工具
yum -y install sysstat

Set the interface color of the top tool

  1. First execute the top command:
top

Enter the display interface of the top command.

  1. Enter the color setting interface:

In the display interface of the top command, use the command Shift + z; to enter the color setting interface.

  1. Modify color:

In the color setting interface, according to the prompt, the parts that can be set include:

    1. Target, that is, which part of the color is set, we can switch between different setting targets by inputting uppercase Sand etc.T
    1. Which color to use for the target, 0-7just enter it.
    1. After setting a color, you can switch between different setting targets through the command in step 1.
    1. End the setting; enter to Enterexit the setting interface.
    1. This step also supports aor wto switch various colors, which is not very easy to use;

After this setting, return to the display interface of the top command. Note that there is no persistent save setting here

  1. Persistence save settings:

In the display interface of the top command, use the command Shift + W; to persist the settings.

Set the color of the command prompt

Zsh settings under MAC:

cat ~/.zshrc

autoload -U colors && colors
PS1="%{
    
    $fg[green]%}%n%{
    
    $reset_color%}@%{
    
    $fg[green]%}%m %{
    
    $fg[yellow]%}%~ %{
    
    $reset_color%}%% "

Settings under Linux:

cat ~/.bashrc
# .bashrc

# set shell prompt
# https://wangdoc.com/bash/prompt.html
PS1="\[\e[31;1m\][\u@\h \W ]$ \[\e[0m\]"

.bashrcThe difference with .bash_profileis that the file suwill not be automatically executed when switching users .bash_profile;

Reference: https://stackoverflow.com/questions/689765/

dns


# CentOS查询哪个工具包支持nslookup
yum provides nslookup

# CentOS系统安装nslookup工具
yum -y install bind-utils

# 查看帮助
man nslookup


# DNS查询工具: nsloopup
$ nslookup www.cncounter.com
Server:		114.114.114.114
Address:	114.114.114.114#53

Non-authoritative answer:
Name:	www.cncounter.com
Address: 8.210.93.167

# DNS查询工具: host
$ host www.cncounter.com
www.cncounter.com has address 8.210.93.167

# DNS查询工具: dig
$ dig github.com

; <<>> DiG 9.10.6 <<>> github.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63069
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;github.com.			IN	A

;; ANSWER SECTION:
github.com.		47	IN	A	20.205.243.166

;; Query time: 81 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Fri Feb 25 10:48:10 CST 2022
;; MSG SIZE  rcvd: 55

MAC related

Unlock download software source restrictions:

sudo spctl --master-disable

Related Links:

Bash script tutorial: https://wangdoc.com/bash/index.html

The Art of Command Line: https://github.com/jlevy/the-art-of-command-line/blob/master/README-zh.md

Github warehouse link: https://github.com/cncounter/translation/tree/master/tiemao_2021/27_shell_alias

Gitee warehouse link: https://gitee.com/cncounter/translation/tree/master/tiemao_2021/27_shell_alias

Guess you like

Origin blog.csdn.net/renfufei/article/details/121948331