最近在在 Linux 服务器上总是遇到已经配置了 JAVA 环境变量,却还是提示 “command not found”,于是特意查了下 Linux 配置环境变量的几个文件的加载顺序。

/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout

其中,几个文件的作用如下:

系统级:
1./etc/environment:是系统在登录时读取的第一个文件,该文件设置的是整个系统的环境,只要启动系统就会读取该文件,用于为所有进程设置环境变量。系统使用此文件时并不是执行此文件中的命令,而是根据而是根据KEY=VALUE模式的代码,对KEY赋值以VALUE,因此文件中如果要定义PATH环境变量,只需加入一行形如 PATH=$PATH:/xxx/bin的代码即可。

2./etc/profile:此文件是系统登录时执行的第二个文件。 为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。并从/etc/profile.d目录的配置文件中搜集shell的设置。(/etc/profile可以用于设定针对全系统所有用户的环境变量,环境变量周期是永久性)。

3./etc/bashrc:是针对所有用户的bash初始化文件,在此中设定的环境变量将应用于所有用户的shell中,此文件会在用户每次打开shell时执行一次。(即每次新开一个终端,都会执行/etc/bashrc)。

阅读全文 »


  • git-completion.bash 保存在你的 root 目录中。

  • git-prompt.sh 保存在你的 root 中。

  • 修改 .bash_profile 文件,添加如下内容。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    # Enable tab completion
    source ~/git-completion.bash

    # colors!
    green="\[\033[0;32m\]"
    blue="\[\033[0;34m\]"
    purple="\[\033[0;35m\]"
    reset="\[\033[0m\]"

    # Change command prompt
    source ~/git-prompt.sh

    export GIT_PS1_SHOWDIRTYSTATE=1
    # '\u' adds the name of the current user to the prompt
    # '\$(__git_ps1)' adds git-related stuff
    # '\W' adds the name of the current directory
    export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"
  • Done !


使用 git status 显示中文文件名乱码:

中文乱码
解决办法,在 Git Bash 中执行:

1
2
#不对0x80以上的字符进行quote,解决git status/commit时中文文件名乱码
git config --global core.quotepath false
阅读全文 »


A remote repository is a repository that’s just like the one you’re using but it’s just stored at a different location. To manage a remote repository, use the git remote command:
远程仓库与你使用的本地仓库差不多,只不过远程仓库存储在另一个地方,如 GitHub码云 等。可以使用以下命令管理管理远程仓库。

$ git remote

  • It’s possible to have links to multiple different remote repositories.
    可以添加多个不同的远程仓库。
  • A shortname is the name that’s used to refer to a remote repository’s location. Typically the location is a URL, but it could be a file path on the same computer.
    短命名用于指向远程仓库的地址。该地址通常为远程仓库的URL,或者是你电脑上的文件路径。
  • git remote add is used to add a connection to a new remote repository.
    git remote add 命令用于添加一个新的远程仓库的连接。
  • git remote -v is used to see the details about a connection to a remote.
    git remote -v 命令用于查看远程仓库的详细信息。
阅读全文 »


由于台风影响,导致计算机中心服务器大规模断电,之前部署的云平台服务器重启后服务不可用。根据之前他们留下的文档,依次启动各个服务。启动 MySQL 时,遇到了如下问题:

“Another MySQL daemon already running with the same unix socket”

主要原因:
Linux 操作系统异常重启后,MySQL 有一个 mysql.sock 文件记录实例的运行状态,因为非正常关机,导致该文件继续存在,MySQL 在启动时会检查该文件,发现已经存在,那么就抛出此错误。

解决办法:
删除 mysql.sock 文件或者改名,重启 MySQL 服务后恢复正常。

阅读全文 »
0%