Linux 技巧

时间:2022-06-11
本文章向大家介绍Linux 技巧,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Linux 技巧

For RedHat Enterprise Linux

系统

Locale

# show system locale
locale

# show system support locale
locale -a

# using utf-8 as system locale
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# support Asia fonts
sudo yum groupinstall Fonts

Network

# check the listening ports and applications on Linux
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo nmap -sTU -O IP-address-Here

工具

Docker

# restart docker services
sudo systemctl stop docker
sudo systemctl daemon-reload
sudo systemctl start docker

# start docker, need to wait few minutes
sudo systemctl restart docker
docker-compose start

# stop docker
docker-compose stop

# stop and clear changes
docker-compose down
docker system prune -f

# start with images
docker-compose up -d

# Re-Install
## cd <compose configure path>
docker-compose down
docker system prune -f
# docker rm -fv $(docker ps -qa)
docker rmi $(docker images -q)
docker-compose pull
docker-compose up -d

# Login docker with root
docker exec -u 0 -it <container id> bash

# Enable docker ssh
docker exec <container id> /usr/sbin/sshd

tmux

有用的链接

什么是tmux

tmux 是一个多通道终端。 最大的好处是:

  • 可以避免终端中断带来的session中断

当运行tmux时,实际上会运行一个tmux service,保持session的运行。

tmux的提出的概念是 tmux / sessions * / windows + / panes + tmux可以管理多个sessions。 一个session有多个windows。 一个windows有多个panes。 每个pane是一个终端。

安装

yum -y install tmux

tmux prefix

prefix 是一个重要的概念。它是一个tmux的快捷键,默认是[ctrl + b]。 比如,退出tmux的命令是

tmux -detach

等价于 [ctrl + b, d]

配置文件

~/.tmux.conf

tmux 命令

  • Help
# list command
tmux list-command

# list shortcut keys
tmux list-keys
  • Sessions

command

shortcut key

meaning

tmux new-session -s [session name]

create an session

tmux attach-session -t [session name]

attach to an (or the only) session

tmux detach-session

prefix + d

detach with the current session

tmux list-sessions

list all sessions

tmux kill-session -t [session name]

kill a session

  • Windows

command

shortcut key

meaning

tmux list-windows

list all windows

tmux kill-window -t [window name]

prefix + &

kill a window

  • Panes

command

shortcut key

meaning

tmux split-window

prefix + %

new a horizontal pane

tmux split-window -v

prefix + "

new a vertical pane

tmux rotate-window

prefix + C-o

rotate panes

tmux select-pane -U

prefix + Up

select the up pane

tmux select-pane -D

prefix + Down

select the down pane

tmux select-pane -L

prefix + Left

select the left pane

tmux select-pane -R

prefix + Right

select the right pane

tmux resize-pane -U

prefix + C-Up

resize the up side

tmux resize-pane -D

prefix + C-Down

resize the down side

tmux resize-pane -L

prefix + C-Left

resize the left side

tmux resize-pane -R

prefix + C-Right

resize the right side

tmux list-panes

list all panes

tmux kill-pane -t [pane name]

prefix + x

kill a pane

  • Save sessions Installation with Tmux Plugin Manager (recommended) Add plugin to the list of TPM plugins in ~/.tmux.conf:
set -g @plugin 'tmux-plugins/tmux-resurrect'

Hit prefix + I to fetch the plugin and source it. You should now be able to use the plugin.

Key bindings prefix + Ctrl-s - save prefix + Ctrl-r - restore