强制修改密码
如果将密码修改得很简单,centos会拒绝修改,可以如下强制修改:
$ sudo su
# echo <password> | passwd --stdin <username>
重定向cd
在 CentOS 系统中,如果您希望在每次使用 cd 命令进入目录后不自动列出所有文件,可以通过修改 Bash 配置文件来实现。
您可以通过编辑用户的 .bashrc 或全局的 /etc/profile 文件来达到目的。请按照以下步骤操作:
-
打开终端。
-
输入
vi ~/.bashrc来编辑当前用户的.bashrc文件;或者使用vi /etc/profile来编辑全局的配置文件,这需要管理员权限(sudo)。 -
在文件末尾添加以下行:
alias cd='cd >/dev/null 2>&1' -
保存并退出编辑器。如果是编辑的
/etc/profile,为了使更改立即生效,需要运行source /etc/profile或重新登录。有时etc/profile未生效,cd进入目录仍会ls, 这时重新source /etc/profile即可。
这样设置后,每次使用 cd 命令切换目录时,不会自动执行 ls 命令,从而不会显示目录下的文件列表。
请注意,上述方法会将 cd 命令的输出重定向到 /dev/null,这意味着即使 cd 命令有输出(通常不会有),也不会在终端上显示。如果您希望恢复默认的行为,只需删除或者注释掉 .bashrc 或 /etc/profile 文件中添加的那行别名配置即可。
CentOS 7安装最新版git
$ yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
查看git版本:
$yum provides git
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.nyist.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
git-1.8.3.1-23.el7_8.x86_64 : Fast Version Control System
Repo : base
git-1.8.3.1-24.el7_9.x86_64 : Fast Version Control System
Repo : updates
git-1.8.3.1-25.el7_9.x86_64 : Fast Version Control System
Repo : updates
git236-2.36.5-1.el7.ius.x86_64 : Fast Version Control System
Repo : ius
Matched from:
Provides : git = 2.36.5-1.el7.ius
git236-2.36.6-1.el7.ius.x86_64 : Fast Version Control System
Repo : ius
Matched from:
Provides : git = 2.36.6-1.el7.ius
git236-2.36.6-1.el7.ius.x86_64 : Fast Version Control System
Repo : @ius
Matched from:
Provides : git = 2.36.6-1.el7.ius
安装git2.36:
$ yum remove git -y #卸载老版本
$ yum install git236 -y
查看新版本
$ git --version
git version 2.36.6
CentOS 7 多版本gcc
担心VCS,verdi不兼容高版本gcc (现在vcs,verdi使用gcc-4.8编译) , 想在centos上安装多个版本gcc,查询资料,决定用Software Collections (SCL)来管理多版本gcc。(SCL类似于anaconda)
-
安装centos-release-scl
$ sudo yum install centos-release-scl -
安装特定版本的
devtoolsetsudo yum install devtoolset-10-gcc*这里安装的是gcc-10.x版本,如果要安装其他版本的GCC,只需将
devtoolset-10替换为相应的版本号,如devtoolset-7。 -
激活特定的devtoolset版本
$ gcc -v 2>&1 | tail -n 1 #激活前版本 gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) $ scl enable devtoolset-10 bash #激活 $ gcc -v 2>&1 | tail -n 1 gcc version 10.2.1 20210130 (Red Hat 10.2.1-11) (GCC) $ exit #退出当前版本 $ gcc -v 2>&1 | tail -n 1 gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)注意,scl激活只对当前终端有效,其他终端仍是默认版本。这种方法不需要手动下载源码编译,而是通过SCL来提供和管理系统范围内的不同版本的工具链。
pip安装太慢
pip安装太慢,使用其他镜像安装:
$ pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
CentOS7 美化
参考文章
初试Tmux
参考链接Tmux新手教学 bryant-video/tmux-tutorial
配置文件~/.tmux.conf:
unbind %
bind | split-window -h -c "#{pane_current_path}"
unbind '"'
bind - split-window -v -c "#{pane_current_path}"
unbind r
bind r source-file ~/.tmux.conf
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5
bind -r m resize-pane -Z
set -g mouse on
set -g mode-keys vi
set -sg escape-time 10 # make delay shorter
### Copy Mode
bind-key -T copy-mode-vi 'v' send -X begin-selection # start selecting text with "v"
bind-key -T copy-mode-vi 'y' send -X copy-selection # copy text with "y"
### Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'jimeh/tmux-themepack'
set -g @plugin 'tmux-plugins/tmux-resurrect' # persist tmux sessions after computer restart
set -g @plugin 'tmux-plugins/tmux-continuum' # automatically saves sessions for you every 15 minutes
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
run '~/.tmux/plugins/tpm/tpm' # Initialize TPM
| 命令 | 功能 |
|---|---|
tmux new -s <session name> |
create a new tmux session |
tmux a -t [Session Name] |
attach to an existing session |
tmux kill-session -t [Session Name] |
Delete a specific Session |
| tmux detach | detach current session |
prefix + ` |
` |
prefix + - |
Split windows up and down |
prefix + ↑↓←→ |
switch panne |
prefix + jkhl |
Resize pane |
prefix + m |
Maximize/Unmaximize current pane |
prefix + c |
create window |
prefix + , |
Rename current active window |
prefix + & |
Kill current window |
prefix + n or p |
Next/Previous window |
prefix + w |
List all Sessions and windows |
prefix + , |
Rename current active window |
prefix+x |
delete current pane |
在tmux中,选择文本时需要按住shift , 用ctrl+shift+c复制,ctrl+shift+v粘贴
网络检测
sudo nethogs