[Share Experiences] deepin使用alias简化命令
Tofloor
poster avatar
ThinkYoung
deepin
2022-06-22 18:41
Author
cd ~ && sudo wget -O .bash_aliases https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/a/alias/.bash_aliases && source ~/.bash_aliases

手动编辑方式:

deepin下

.bash_aliases文件内容:

#alias
############################################################################
# cd ~ && sudo wget -O  .bash_aliases   https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/a/alias/.bash_aliases  &&  source  ~/.bash_aliases

# https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/a/alias/.bash_aliases
######################################################
# aliases collect by 逍遥(ThinkYoung) 
######################################################


# [system cmd]
alias alias-version="echo -e '\033[32m     V23.05.11     \033[0m'  "


alias install="sudo apt install -y "
alias uninstall="sudo apt autoremove --purge  -y "
alias download="sudo apt download "
alias update="sudo apt update -y"
alias upgrade="sudo apt upgrade -y"
alias autoremove=" sudo apt autoremove -y"
alias full-upgrade="sudo apt update && sudo apt dist-upgrade -y "
alias dpkg-scan="dpkg-scanpackages"
alias pubkey-add="sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "

alias py="python "
alias json="jq"

# folder rename {命令:mv 当前目录  新目录}
alias rename="sudo mv"
# 使用trash-cli做为删除,可进回收站
alias del="trash-put "

# 列出系统中所有进程:
alias process="ps -aux"
# 按名称杀死进程:
alias kill="sudo pkill"
# 显示系统系统总使用内存和空闲内存:
alias mem-info="free -h"
# 显示系统 CPU 框架结构、CPU 数量、线程数等:
#alias cpu-info="lscpu"
# current CPU Frequency
alias cpu-info="sudo i7z"
# Inxi查看硬件信息
alias device-info="inxi -Fxi"
# 显示系统总磁盘大小:
alias disk-info="df -h"
# 清屏
alias cls="clear"
# 查本机实际IP
alias ip-info="inxi -i"
alias ip-info2='echo -e "\n外网IP:" && curl ipinfo.io/ip && echo -e "\n内网IP:" && ip addr show '

# python easy server
alias web='f(){ python3 -m http.server 8000 --directory $1; }; f'
alias web3='f(){ python3 -m http.server 8000 --directory $1; }; f'
alias web2='f(){ python2 -m SimpleHTTPServer $1; }; f'
# greeting info
alias logo="screenfetch"
# weather 必须填写地址
alias weather=" inxi -W Shenyang,China && curl wttr.in "
# date-first 查询系统初装时间
alias date-first="ls -lact --full-time /etc |  tail -1 |  awk '{print \$6,\$7}' "

# open
alias goto="xdg-open "
# open
alias open="xdg-open"
# so 搜索引擎
alias so='f(){ xdg-open http://baidu.com/s?wd=$1; }; f'
alias baidu='f(){ xdg-open http://baidu.com/s?wd=$1; }; f'
alias toutiao='f(){ xdg-open https://so.toutiao.com/search/?keyword=$1; }; f'



# tar.xz 
#tar xvJf ***.tar.xz
alias untarxz="tar xvJf "
# 压缩xz
alias   tarxz="tar -cJf `date +%Y%m%d`-$RANDOM.tar.xz "

# tar.gz
# 解压缩 xxx.tar.gz #tar -zxvf xxx.tar.gz
alias untargz="tar -zxvf "
# 压缩aaa bbb目录为xxx.tar.gz #tar -zcvf xxx.tar.gz aaa bbb
alias   targz="tar -zcvf `date +%Y%m%d`-$RANDOM.tar.gz "

# tar
# 解压缩 xxx.tar #tar -xvf xxx.tar.gz
alias untar="tar -xvf "
# 压缩aaa bbb目录为xxx.tar #tar -cvf xxx.tar.gz aaa bbb
alias mktar="tar -cvf `date +%Y%m%d`-$RANDOM.tar "

# zstd
#   zstd ***
alias zst="zstd "
# unztsd ***
alias unzst="unzstd "


##########################################################

# [user soft]

#alias steam="/usr/bin/steam"
alias edge="/usr/bin/microsoft-edge-stable --start-fullscreen"
alias thunder="/opt/apps/com.xunlei.download/files/start.sh"
alias wechat="/opt/apps/com.qq.weixin.deepin/files/run.sh"
alias lxmusic="/opt/lx-music-desktop/lx-music-desktop"
alias ths="/opt/apps/cn.com.10jqka/files/HevoNext.B2CApp"

alias csgo="steam steam://rungameid/730"
alias dota2="steam steam://rungameid/570"
alias tf2="steam steam://rungameid/440"

alias vscode="/usr/share/code/code --unity-launch"
alias dbeaver="/usr/share/dbeaver-ce/dbeaver"
alias nxshell="/opt/NxShell/nxshell"
alias wps="/opt/apps/cn.wps.wps-office/files/bin/wps"

alias mycheck="curl -s https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/s/shell/mem.sh |sudo bash "

##########################################################

# [deepin soft]
alias appstore="deepin-home-appstore-client"
#alias spark="spark-store"
alias folder="/usr/bin/dde-file-manager"
alias monitor="deepin-system-monitor"
alias control="dde-control-center --show"
alias calc="deepin-calculator"
alias txt="deepin-editor"


##########################################################


# [folder]

# theme icons folder
alias theme-go="sudo dde-file-manager /usr/share/icons"

# backgrounds folder
alias background-go="sudo dde-file-manager /usr/share/backgrounds/"
alias wallpapers-go="sudo dde-file-manager /usr/share/wallpapers/"


# applications folder
alias app-go="sudo dde-file-manager /usr/share/applications/"

# bt-panel icons folder
alias bt-go="sudo dde-file-manager /www/wwwroot"






##########################################################

# [deepin config]
# EZ Do
alias ez="/opt/EZ/do.sh"
alias ez-cfg="sudo nano /opt/EZ/do.sh"

# 命令别名 {source .bash_aliases}

alias alias-ins="cd ~ && sudo wget -O  .bash_aliases   https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/a/alias/.bash_aliases  &&  source  ~/.bash_aliases"
alias alias-up="cd ~ && sudo wget -O  .bash_aliases    https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/a/alias/.bash_aliases  &&  source  ~/.bash_aliases"
alias alias-cfg="sudo nano ~/.bash_aliases"
alias alias-act="source  ~/.bash_aliases"
alias alias-go="sudo dde-file-manager  ~/"

alias spark-ins="cd /usr/bin && sudo wget -O  spark-console   https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/s/spark/spark-console.py  &&  sudo chmod +x ./spark-console"
alias spark-cfg="sudo nano /usr/bin/spark-console "
alias spark="spark-console"


# 分区
alias fstab-cfg="sudo nano /etc/fstab"
# mime
alias mime-cfg="sudo nano  ~/.config/mimeapps.list"

# 域名映射
alias hosts-cfg="sudo nano /etc/hosts"
alias hosts-ins="echo '192.168.124.6        home' | sudo tee -a  /etc/hosts"
# 环境配置 {source /etc/profile}
alias profile-cfg="sudo nano /etc/profile"
alias profile-act="source /etc/profile"
# 用户组
alias passwd-cfg="sudo nano /etc/passwd"
# 定时任务
alias crontab-cfg="sudo nano /etc/crontab"
# 软件源
alias source-cfg="sudo nano /etc/apt/sources.list"

# autostart
alias autostart-go="sudo xdg-open ~/.config/autostart/"

# GRUB {sudo update-grub}
alias grub-cfg="sudo nano /etc/default/grub"
alias grub-act="sudo update-grub"




############################################################################


# [soft install]

# Init installer
alias init-ins="cd ~ &&  wget -O  init.sh  https://gitee.com/thinkyoung/ENV/raw/master/Deepin/pool/main/i/init/init.sh  &&  sudo bash init.sh"

# One installer 装机必备 wechat,thunder,wps,spark-store,baidunetdisk,dbeaver,nxshell,edge,lxmusic,steam
alias one-ins="sudo apt-get install com.qq.weixin.deepin com.xunlei.download cn.wps.wps-office spark-store com.baidu.baidunetdisk io.dbeaver.community com.nxshell.nxshell microsoft-edge-stable lx-music-desktop steam"

alias start-ins="sudo apt install /data/packages/deepinstore/pool/deepinstore/*.deb"



# kernel stable installer
alias kernel-ins="sudo apt-get install linux-image-deepin-stable-amd64 linux-headers-deepin-stable-amd64"

# intel genic integrated graphics/video card driver installer mesa驱动
alias display-ins="sudo  apt  install  libgl1-mesa-dri  libgl1-mesa-dri:i386  mesa-vulkan-drivers  mesa-vulkan-drivers:i386  libvulkan1  libvulkan1:i386  'vulkan-utils|vulkan-tools'"

# vulkan
alias display-ins="sudo apt install mesa-vulkan-drivers libvulkan1 vulkan-tools vulkan-validationlayers"


# spark-store
alias spark-store-ins="wget -O spark.deb https://gitee.com/deepin-community-store/spark-store/releases/download/4.2.6.2/spark-store_4.2.6.2_amd64.deb && sudo apt install ./spark.deb"

# vscode
alias vscode-ins="aria2c -c -x 16 -s 16 --header 'User-Agent: netdisk' -d '/tmp' -o 'vscode.deb' 'https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64' --summary-interval=1  && sudo apt install /tmp/vscode.deb"

# dbeaver https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb  https://github.com/dbeaver/dbeaver/releases/
alias dbeaver-ins="aria2c -c -x 16 -s 16 --header 'User-Agent: netdisk' -d '/tmp' -o 'dbeaver.deb' 'https://download.dbeaver.com/community/22.2.2/dbeaver-ce_22.2.2_amd64.deb' --summary-interval=1  && sudo apt install /tmp/dbeaver.deb"

# tabby
alias tabby-ins="aria2c -c -x 16 -s 16 --header 'User-Agent: netdisk' -d '/tmp' -o 'tabby.deb' 'https://ghproxy.com/https://github.com/Eugeny/tabby/releases/download/v1.0.184/tabby-1.0.184-linux-x64.deb' --summary-interval=1  && sudo apt install /tmp/tabby.deb"

# yum installer
alias yum-ins="sudo apt-get install build-essential yum"

# BT-panel installer
alias bt-ins="wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh ed8484bec"

# oneinstack installer {https://oneinstack.com/install/}
alias oneinstack-ins="apt-get -y install wget screen && wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && cd oneinstack && screen -S oneinstack && ./install.sh"

# lnmp installer {https://www.lnmp.org/install.html}
alias lnmp-ins="wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz -cO lnmp1.9.tar.gz && tar zxf lnmp1.9.tar.gz && cd lnmp1.9 && ./install.sh lnmp"

# phpstudy installer {https://www.xp.cn/linux.html}
alias phpstudy-ins="wget -O install.sh https://notdocker.xp.cn/install.sh && sudo bash install.sh"

# C env installer
alias c-ins="sudo apt-get -y install libreadline-dev libpcre3-dev libssl-dev cmake perl libncurses5-dev build-essential gdb  -y"

# Qt installer{# 打开编辑文件 sudo deepin-editor /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf #修改第一行:/usr/lib/x86_64-linux-gnu/qt4/bin#改为/usr/lib/x86_64-linux-gnu/qt5/bin}
alias qt-ins="sudo apt update && sudo apt install git qt5-qmake qt5-default && sudo apt install debhelper libdtkwidget-dev libdtkgui-dev zlib1g zlib1g-dev qtbase5-dev"

# Glade installer
alias glade-ins="sudo apt install glade"

# DTK installer
alias dtk-ins="sudo apt -y install qt5-default qtcreator cmake g++ git libdtkwidget-dev libdtkgui-dev libdtkcore-dev deepin-sdk qtcreator-template-dtk"

#Anaconda3 installer
alias anaconda3-ins="wget -O anaconda.sh  https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh && sudo bash anaconda.sh"

# python3 installer
alias python3-ins="sudo apt-get install python3 python3-venv python3-pip"

# docker installer
alias docker-ins="curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun"

# dotnet installer {https://dotnet.microsoft.com/zh-cn/download}
alias dotnet-ins="wget -O dotnet-install.sh https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh && sudo bash dotnet-install.sh"

# lua installer {http://www.lua.org/start.html}
alias lua-ins="curl -R -O http://www.lua.org/ftp/lua-5.4.4.tar.gz && tar zxf lua-5.4.4.tar.gz && cd lua-5.4.4 && make all test && sudo make install"

# rust installer{https://www.rust-lang.org/learn/get-started}
alias rust-ins="curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"

# go installer{https://golang.google.cn/doc/install    need   export PATH=$PATH:/usr/local/go/bin}
alias go-ins="wget -O go.linux-amd64.tar.gz  https://golang.google.cn/dl/go1.18.3.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go.linux-amd64.tar.gz"

# nodejs installer{https://nodejs.org/en/download/     V16.15.1 }
alias nodejs-ins="wget -O nodejs.linux-x64.tar.gz  https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.gz && sudo rm -rf /www/server/nodejs/v16.15.1 && sudo tar -C /www/server/nodejs/ -xzf nodejs.linux-x64.tar.gz && sudo mv /www/server/nodejs/node-v16.15.1-linux-x64 /www/server/nodejs/v16.15.1 && sudo echo 'export NODE_HOME=/www/server/nodejs/v16.15.1' | sudo tee -a /etc/profile &&  sudo echo 'export PATH=\$PATH:\$NODE_HOME/bin' | sudo tee -a /etc/profile &&  sudo echo 'export NODE_PATH=\$NODE_HOME/lib/node_modules' | sudo tee -a /etc/profile && source /etc/profile"

# java
alias java-ins="sudo apt install openjdk-8-jdk"

##########################################################

================================

sudo deepin-editor .bashrc

source .bashrc

Reply Favorite View the author
All Replies
公子独白
deepin
2022-06-22 22:16
#1

楼主用心,但是有些命令感觉是多此一举。就像mv ===> rename真的是简化吗?

还有好多不需要sudo权限的命令,没有必要加sudo

Reply View the author
DebuggerX
deepin
2022-06-23 03:06
#2

看到有对apt命令的别名简化,说一下这里的问题:

别名会导致原本命令的参数补全失效,具体来说,正常情况下,如果输入 sudo apt install deepin-te 后按 Tab 就能补全成 deepin-terminal,但是用别名的话此时按 Tab 键就没法这么智能得补全了。

解决办法:

# 简化 apt 操作
alias aarm='sudo apt-get autoremove --purge'
alias ainstall='sudo apt-get install'
alias arm='sudo apt-get --purge remove'

# 为简化后的 apt 操作命令赋予 tab 键补全的能力
_apt_get_install()
{
    local cur prev words cword
    _init_completion || return

    special="install"
    COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
                2> /dev/null ) )
    return 0
} &&

_apt_get_remove()
{
    local cur prev words cword
    _init_completion || return

    special="remove"
    if [[ -f /etc/debian_version ]]; then
    # Debian system
    COMPREPLY=( $( \
            _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
    else
        # assume RPM based
        _xfunc rpm _rpm_installed_packages
    fi
    return 0
} &&

complete -F _apt_get_install ainstall
complete -F _apt_get_remove arm

参考: 个人对 Linux 的一些偏好设置

Reply View the author
ThinkYoung
deepin
2022-06-29 19:57
#3
DebuggerX

看到有对apt命令的别名简化,说一下这里的问题:

别名会导致原本命令的参数补全失效,具体来说,正常情况下,如果输入 sudo apt install deepin-te 后按 Tab 就能补全成 deepin-terminal,但是用别名的话此时按 Tab 键就没法这么智能得补全了。

解决办法:

# 简化 apt 操作
alias aarm='sudo apt-get autoremove --purge'
alias ainstall='sudo apt-get install'
alias arm='sudo apt-get --purge remove'

# 为简化后的 apt 操作命令赋予 tab 键补全的能力
_apt_get_install()
{
    local cur prev words cword
    _init_completion || return

    special="install"
    COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
                2> /dev/null ) )
    return 0
} &&

_apt_get_remove()
{
    local cur prev words cword
    _init_completion || return

    special="remove"
    if [[ -f /etc/debian_version ]]; then
    # Debian system
    COMPREPLY=( $( \
            _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
    else
        # assume RPM based
        _xfunc rpm _rpm_installed_packages
    fi
    return 0
} &&

complete -F _apt_get_install ainstall
complete -F _apt_get_remove arm

参考: 个人对 Linux 的一些偏好设置

非常感谢 👍 👍👍

Reply View the author
然也
deepin
2023-03-08 18:09
#4
It has been deleted!
然也
deepin
2023-03-08 18:10
#5

文件中这一行:alias download="sudo apt downliad ",在系统中执行不成功啊,downliad好像写错了,扩展不出来啊

Reply View the author
ThinkYoung
deepin
2023-03-08 21:47
#6
然也

文件中这一行:alias download="sudo apt downliad ",在系统中执行不成功啊,downliad好像写错了,扩展不出来啊

👍 感谢指正,已修改!

Reply View the author
SamLukeYes
deepin
2023-03-08 22:54
#7

个人不是很喜欢这种滥用别名的做法。除了沙发提到的以外,我再补充两点具体问题:

  1. rename 是 util-linux 中的一个命令,和 mv 用法有所不同,直接把 rename 当作 mv 的别名容易造成困惑。
  2. del 是某些 shell 中的关键字,也不适合作为别名。
Reply View the author
ThinkYoung
deepin
2023-03-09 00:27
#8
SamLukeYes

个人不是很喜欢这种滥用别名的做法。除了沙发提到的以外,我再补充两点具体问题:

  1. rename 是 util-linux 中的一个命令,和 mv 用法有所不同,直接把 rename 当作 mv 的别名容易造成困惑。
  2. del 是某些 shell 中的关键字,也不适合作为别名。

大佬们说的很对!

别名命名这个事情,就像给变量命名一样,仁者见仁,智者见智

每个人都有自己的使用习惯,自己用好便好!

我之所以这么起,就是无需大脑记忆,不废脑,跨系统我还这么用,随便迁移

del滥用 是避免平时remove命令滥用! 谁会质疑remove的杀伤力呢? 不还是在随意用remove嘛?

其实 反过来说 为啥不是那些工具包也是随意使用了关键字 在滥用呢?

滥用就该覆盖掉滥用!

大家都谦虚,不敢用关键字,所以就有个别包使用了,但是它标准嘛?

都不敢用editor,所以大家用了deepin-editor kylin-editor(举个例子) 但是editor谁用了? 难道editor成了关键字?

是deepin-editor也好,deepin-wine-editor也好,deepin-dde-editor也好,其实editor就是给用户去决定的

保守/懒策略肯定是对的,但肯定有不足,贪婪策略肯定激进,但不一定都是错的!

我觉得linux精神是free的 不是死的!

Reply View the author
SamLukeYes
deepin
2023-03-09 01:52
#9
ThinkYoung

大佬们说的很对!

别名命名这个事情,就像给变量命名一样,仁者见仁,智者见智

每个人都有自己的使用习惯,自己用好便好!

我之所以这么起,就是无需大脑记忆,不废脑,跨系统我还这么用,随便迁移

del滥用 是避免平时remove命令滥用! 谁会质疑remove的杀伤力呢? 不还是在随意用remove嘛?

其实 反过来说 为啥不是那些工具包也是随意使用了关键字 在滥用呢?

滥用就该覆盖掉滥用!

大家都谦虚,不敢用关键字,所以就有个别包使用了,但是它标准嘛?

都不敢用editor,所以大家用了deepin-editor kylin-editor(举个例子) 但是editor谁用了? 难道editor成了关键字?

是deepin-editor也好,deepin-wine-editor也好,deepin-dde-editor也好,其实editor就是给用户去决定的

保守/懒策略肯定是对的,但肯定有不足,贪婪策略肯定激进,但不一定都是错的!

我觉得linux精神是free的 不是死的!

如果你是嫌命令长,为啥不直接用有自动提示、自动补全的 shell 呢,还省得起那么多名字doubt

Reply View the author
ThinkYoung
deepin
2023-03-09 03:15
#10
SamLukeYes

如果你是嫌命令长,为啥不直接用有自动提示、自动补全的 shell 呢,还省得起那么多名字doubt

补全 如果你用deepin-dde-editor 你得补全几次呢?

alias folder="/usr/bin/dde-file-manager"
alias monitor="deepin-system-monitor"
alias control="dde-control-center --show"
alias calc="deepin-calculator"
alias txt="deepin-editor"

看看 有时候带deepin 有时候直接dde 补全 你能直接找到吗?

deepin 的命名规则是按UI环境命名的 不是统一命名头

Reply View the author