Linux 学习文档

学习里程2019

更改Swap内存使用

1
sudo gedit /etc/sysctl.conf

在文件内添加以下命令, 其中值为0时为最大限度的使用物理内存:

1
vm.swappiness=10

调整最大文件打开数

1
sudo gedit /etc/profile

在文件内添加以下命令:

1
ulimit -Sn 51200 # -S 软限制 -n 可打开最大文件数

多核启动(Ubuntu)

该处存疑, ubuntu环境systemd默认即为并行启动.

1
sudo gedit /etc/init.d/rc

更改以下命令:

1
CONCURRENCY=none -> CONCURRENCY=makefile

读取和设置IDE或SCSI硬盘参数

1
2
3
sudo hdparm /dev/sda # 显示硬盘的相关设置
sudo hdparm -T /dev/sda # 显示硬盘的读取速度
sudo hdparm -i /dev/sda # 显示硬盘的硬件规格信息

启动过程分析

1
2
3
4
5
systemd-analyze # 查看开机过程在内核/用户空间消耗的时间
systemd-analyze blame # 按照耗费时间顺序, 输出启动每个单元耗费的时间
systemd-analyze critical-chain # 在开机过程的一些时刻, 需要特定的单元成功启动了才能继续. 查看在启动链中哪些单元处于这种危急时刻
systemd-analyze plot > plot.svg # 生成类似于bootchart的开机过程图表
systemd-analyze time # 查看开机时间

卸载命令(Ubuntu)

1
2
3
4
5
6
7
sudo apt autoremove # 删除为了满足依赖而安装的, 但现在不再需要的软件包(包括已安装包), 保留配置文件, 慎用
sudo apt remove # 删除已安装的软件包(保留配置文件), 不会删除依赖软件包, 保留配置文件
sudo apt purge # 删除已安装的软件包(不保留配置文件), 删除软件包, 同时删除相应依赖软件包
sudo apt remove --purge # 同apt-get purge
sudo apt autoclean # 删除为了满足某些依赖安装的, 但现在不再需要的软件包, 本命令会删除/var/cache/apt/archives/下已经过期的deb
sudo apt clean # 删除已经安装过的的软件安装包, 即自动将/var/cache/apt/archives/下的所有deb删掉, 相当于清理下载的软件安装包
dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P # 理dpkg的列表中有“rc”状态的软件包
1
2
3
dpkg -l | grep <package> # 查看软件的状态
dpkg -P / dpkg --purge # 安装文件和配置文件都删除
dpkg --remove # 删除安装的文件,但不删除配置文件

学习里程2020

zsh的安装与配置

  • 安装zsh, 并将其设置为默认shell:

    1
    2
    3
    sudo yum install zsh # 安装zsh
    chsh -l # 查看shell路径
    sudo chsh -s $(which zsh) # 设置默认shell
  • 安装oh-my-zsh:

    1
    sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" # 注意系统中是否安装了curl
  • 通过修改~/.zshrc文件进行修改:

    1
    ZSH_THEME="ys" # 配置默认主题为ys

    如果想更改主题的相关配置, 可以编辑~/.oh-my-zsh/themes/ys.zsh-theme文件:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    cp ys.zsh-theme ys.zsh-theme.bak # 进行备份
    vim ys.zsh-theme
    # 将ys主题的主机名称去掉, 更改最后的PROMPT
    PROMPT="
    %{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
    %(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
    %{$fg[white]%}in \
    %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
    ${hg_info}\
    ${git_info}\
    \
    %{$fg[white]%}[%*] $exit_code
    %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
  • 相关插件安装, 下载位置可以放在~/.oh-my-zsh/customs/plugins/文件夹中, 相关具体用法请搜索:

    1
    2
    3
    git clone git://github.com/zsh-users/zsh-autosuggestions # 自动补全, 通过方向键
    git clone git://github.com/zsh-users/zsh-syntax-highlighting # 命令高亮
    git clone git://github.com/joelthelion/autojump.git # 目录跳转

    其中, autojump需要进行安装:

    1
    2
    cd autojump
    ./install.py # 会在~目录下生成.autojump文件夹

    此外, 需要在~/.zshrc中进行相关配置, 插件才会有效:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    plugins=(
    git
    autojump
    zsh-autosuggestions
    zsh-syntax-highlighting
    )
    # 在文件末尾添加:
    [[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
    source ~/.zshrc # 生效

zsh的相关问题

  • xshell使用oh-my-zsh时, home键和end键无效的解决方法:

    1
    2
    3
    4
    5
    cat <<ENDOF >> ~/.zshrc # 提示heredoc>时输入
    bindkey '\e[1~' beginning-of-line # home键
    bindkey '\e[4~' end-of-line # end键
    ENDOF # 结束输入
    source ~/.zshrc
  • 使用zsh登陆某一用户时提示: Cannot execute zsh: No such file or directory

    1
    2
    cat /etc/passwd
    root:x:0:0:root:/root:/bin/zsh # 查看其中的root和自己设定的用户是否路径正常
  • root用户设置zsh:

    1
    2
    3
    ln -s $HOME/.oh-my-zsh /root/.oh-my-zsh
    ln -s $HOME/.zshrc /root/.zshrc
    ln -s $HOME/.autojump /root/.autojump

    此时, 进入root用户时会提示: [oh-my-zsh] For safety, we will not load completions from these directories until相关信息, 可以知道权限出现问题:

    1
    2
    3
    4
    5
    6
    chmod 755 /.oh-my-zsh
    chmod 755 /.oh-my-zsh/plugins
    chmod 755 /.oh-my-zsh/plugins/[relative plugins]
    # 或者, 通过在.zshrc文件中的第一行添加命令
    ZSH_DISABLE_COMPFIX=true
    source ~/.zshrc
0%