本文介绍.bash_profile文件的编写规则,给出.bashrc, .tmux.conf, .vimrc中常用的配置,还有一个有趣的配置,可以实现登陆后在命令行输出你喜欢的符号。
这个文件用来设置用户环境变量,语法遵循shell
定义变量时变量名和等号之间不能有空格,如your_name="kly"
使用一个定义过的变量,只要在变量名前面加美元符号即可。如打印变量名:echo $your_name或者echo ${your_name}
原本应该换行的代码写到一行时,需要用分号加空格;进行分隔
使用alias命令给某个路径下的可执行程序起别名:alias [别名]=[指令名称]
使用export命令设置环境变量
export PATH:定义环境变量PATHexport CUDA_HOME=/ssd1/shared/local/cuda-10.1:定义并设置环境变量CUDA_HOMEexport PATH=/ssd1/shared/local/anaconda3/bin:$PATH:为环境变量PATH增加一条记录(linux环境变量是用冒号隔开的)循环语句示例,批量修改路径下week01等文件夹名为chapter01
for ff in week??
do
echo ${ff} # 打印原文件名 week01等
echo ${ff#week} # 打印去掉week的名字 01等, 掐头用# 去尾用%
mv $ff chapter${ff#week}
done更详细的shell语法规则见:https://www.runoob.com/linux/linux-shell.html
Linux命令大全:https://www.runoob.com/linux/linux-command-manual.html
修改完.bash_profile文件后需要运行命令source ~/.bash_profile来使文件生效
.bashrc .tmux.conf .vimrc 不显示中文,在.bashrc编辑
# 先用locale命令看一下现在采用的编码
# 用locale -a看一下支持的编码,然后改.bashrc
export LANGUAGE="zh_CN:zh"
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8".vimrc
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set number "显示行号"
set autoread
set autowrite
set nocp
set ruler
set autoindent
set cindent
set tabstop=4 "tab缩进4位"
syn on
color desertvim ~/.tmux.conf
set -g mouse on激活:tmux source ~/.tmux.conf
如果开启鼠标模式后无法复制,解决方法:按住Fn,然后选择自己需要的文本。选中后使用command+C/V
在ssh登录后,默认打印上一次登录的日期时间,其实可以通过设置打印自定义的内容如下图

vim /etc/ssh/sshd_config
# 加入下面两句话
PrintMotd yes
PrintLastLog no
# 编辑完后重启ssh
sudo service ssh restart
# 或者 sudo service restart sshd
# 在motd文件中写上想输出的内容即可
vim /etc/motd