平时管理 linux 系统,一遍又一遍重复命令,太枯燥了。于是自己封装了一些好用的函数。
不想直接修改 /etc/bash.bashrc 文件,于是通过 source 引入我自定义的 bashrc.sh 文件。
$vim /etc/bash.bashrc
# 最后加上引用文件
source /e/develop/shell/bashrc.sh#!/bin/bash
#!/bin/bash #环境变量 programs=/usr/local php=$programs/php zookeeper=$programs/zookeeper redis=$programs/redis JAVA_HOME=$programs/java8 PATH=$PATH:$JAVA_HOME/bin:$php/bin:$zookeeper/bin:$redis/bin #history 配置 export HISTSIZE=1000; HISTTIMEFORMAT='%F '; HISTCONTROL="ignoredups" export HISTIGNORE="ls:ll:pwd:history" alias dir-mod="sudo chmod -R" alias reload="source /etc/bash.bashrc" alias command-list="compgen -ac" ### 解压文件 ### alias tar-programs="sudo tar -C $programs -xvf" ### 切换目录 ### alias cd-programs="cd /usr/local" alias cd-download="cd ~/Downloads" alias search="apt search" alias install='sudo apt install -y' alias upgrade='sudo apt upgrade -y' alias purge='sudo apt-get purge' alias update="command 'sudo apt update && apt list --upgradable'" alias autoclean="command 'sudo apt-get autoremove && sudo apt-get autoclean'" #解压到 Downloads 目录,并删除压缩包,切换到Downloads 目录 function tar-download(){ local file="$1" cd ~/Downloads && / tar -C ~/Downloads -xvf $file && / trash ./$file && / } #写入日志 function log(){ local file="$1" local text="$2" if [ -n "$text" ]; then text=$file file='debug' fi echo -e "$text" >> /tmp/"$file.log"; } function red(){ echo -e "