linuxalias命令别名并输出其原始命令

编程

alias 功能固然好用,但在快捷方便的同时,隐藏了原始命令的结节。久而久之,不记得原始命令是什么了,因些,我想到了实现原命令输出,以作为提示。先看效果图吧。

 

 

代码如下:

### 开始自定义 ###

#环境变量

PROGRAMS=/usr/local

PHP=$PROGRAMS/php7.4

ZOOKEEPER=$PROGRAMS/zookeeper

JAVA_HOME=$PROGRAMS/java8

PATH=$PATH:$JAVA_HOME/bin:$PHP/bin:$ZOOKEEPER/bin

#history 配置

export HISTSIZE=1000; HISTTIMEFORMAT="%F "; HISTCONTROL="ignoredups"

export HISTIGNORE="ls:ll:pwd:history"

#定义编辑器

alias open="code"

alias open-bashrc="command "code /etc/bash.bashrc" && green ">> [ctrl + win + o ]""

alias reload-bashrc="command "source /etc/bash.bashrc""

alias open-phpini="open $PHP/lib/php.ini"

alias tar-download="tar -C ~/Downloads -xvf"

alias tar-programs="sudo tar -C $PROGRAMS -xvf"

alias tar-it-="tar -xvf"

#查看

alias port="command "sudo netstat -nltp | grep" "

alias process="command "ps -ef | grep" "

#切换目录

alias cd-soft="cd /mnt/hgfs/soft"

alias cd-develop="cd /mnt/hgfs/develop"

alias cd-programs="cd /usr/local"

alias cd-download="cd ~/Downloads"

#Apache

alias apache-start="sudo apachectl start"

#mysql

alias mysql-stop="sudo service mysqld stop"

alias mysql-start="sudo service mysqld start"

#nginx

alias nginx-start="sudo nginx -s start"

alias nginx-stop="sudo nginx -s stop"

#清理没有名字的镜像

alias docker-clear="command "docker rmi " "$(docker images -f "dangling=true" -q)""

#停止多个相同进程

kill-all(){

ps -ef| grep $1 |grep -v grep |awk "{print $2}" | xargs kill -9

}

#批量运行 redis 服务

redis-start(){

start=$1

end=$2

dir=$3

if [ -z "$dir" ];then

dir=""

fi

while(( $start<=$end ))

do

redis-server $dir$start.conf

let "start++"

done

}

#进入容器

docker-exec(){

command "docker exec -it $1 /bin/bash"

}

#查看容器IP

docker-ip(){

item=$1

if [ -z "$item" ];then

item="$(docker ps -aq)"

fi

command "docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" " "$item"

}

#删除卷

docker-volume-rm(){

item=$1

if [ -z "$item" ];then

item="$(docker volume ls -q)"

fi

command "docker volume rm" "$item"

}

#停止容器

docker-stop(){

item=$1

if [ -z "$item" ];then

item="$(docker ps -aq)"

fi

command "docker stop" " $item"

}

#删除容器

docker-rm(){

item=$1

if [ -z "$item" ];then

item="$(docker ps -aq)"

fi

command "docker rm" "$item"

}

red(){ echo -e "33[31m$133[0m"; }

green(){ echo -e "33[32m$133[0m"; }

command(){

local command="$1"

local param="$2"

red ">> $command $param"

eval $command $param

}

  

以上是 linuxalias命令别名并输出其原始命令 的全部内容, 来源链接: utcz.com/z/515291.html

回到顶部