zoukankan      html  css  js  c++  java
  • linux alias 命令别名并输出其原始命令

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

    /etc/bash.bashrc 文件追加代码如下:
    ### 开始自定义 ###
    
    #环境变量
    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 close-bashrc="command 'source /etc/bash.bashrc'"
    alias open-phpini="open  $PHP/lib/php.ini"
    alias open-readme="open README.md"
    
    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"
    
    
    #停止多个相同进程
    function kills(){
    	ps -ef| grep $1 |grep -v grep |awk '{print $2}' | xargs kill -9
    }
    
    #批量运行 redis 服务
    function redis-start(){
    	local start=$1
    	local end=$2
    	local dir=$3
    	if [ -z "$dir" ];then
        		dir=''
    	fi
    	while(( $start<=$end ))
    	do
    	    redis-server $dir$start.conf 
    		let "start++"
    	done
    
    }
    
    
    function docker-image(){
    
        local cmd="$1"
    	local param="$2"
    
        case "$cmd" in
            'clean')
                command 'docker image rm' '$(docker image ls -f "dangling=true" -q)'
            ;;
        esac
    
    }
    
    function docker-volume(){
    
        local cmd="$1"
    	local param="$2"
    
        case "$cmd" in
            'rm')
                if [ -z "$param" ];then
                    param='$(docker volume ls -q)'
                fi
                command "docker volume rm" "$param"
            ;;
            'clean')
                command "docker volume prune"
            ;;
        esac
    }
    
    
    function docker-container(){
    
    	local cmd="$1"
    	local param="$2"
    
    	case "$cmd" in
    		'stop')
                if [ -z "$param" ];then
                    param='$(docker ps -q)'
                fi
                command "docker stop" "$param" 
            ;;
            'start')
                if [ -z "$param" ];then
                    param='$(docker container ls -aq)'
                fi
                command "docker container start" "$param" 
            ;;
    		'ip')
                if [ -z "$param" ];then
                    param='$(docker container ls -aq)'
                fi
                echo $param
                command "docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'" "$param"
            ;;
            'rm')
                if [ -z "$param" ];then
                    param='$(docker container ls -aq)'
                fi
                command "docker container rm -f" "$param" 
            ;;
            'exec')
                command "docker container exec -it $param /bin/bash"
            ;;
    
    	esac
    
    }
    
    
    function red(){ echo -e "33[31m$133[0m";}
    function green(){ echo -e "33[32m$133[0m";}
    
    function command(){
    
    	local command="$1" 
    	local param="$2"
    
    	red ">> $command $param"
    	eval $command $param
    }
    
    #非标准的查看版本写这里
    function version(){
    	local name="$1"
    	local version='--version'
    	case "$name" in
    		'java' ) version='-version';;
    	esac
    	command $name $version
    }
    

      

  • 相关阅读:
    2019.7.17东湖大数据页面三
    2019.7.17东湖大数据页面二
    2019.7.17东湖大数据页面一
    css的使用方法和css选择器
    css定位和浮动
    form表单的理解及用法
    CSS中路径及form表单的用法
    关于新手html的认识 以及对table的基本用法
    网络编程和并发34题
    爬虫day01
  • 原文地址:https://www.cnblogs.com/zbseoag/p/12668622.html
Copyright © 2011-2022 走看看