linux 查看端口占用
lsof -i:端口号
Linux 启动程序的时候报 Text file busy
lsof | grep exec
查看文件被占用的进程号,然后 kill
便可。
macOS 查看路由
netstat -nr -f inet
Add sudo permission to normal account
Create new file under /etc/sudoers.d/
directory, then add following text.
user ALL=(ALL) NOPASSWD: ALL
Note that user
is the account name of the user.
kill process with pattern in bulk
kill $(ps aux | grep './process_pattern' | awk '{print $2}');
Install Mosh on Alma/CentOS/RHEL
yum install epel-release -y
yum install mosh -y
# or
dnf install mosh
See which package provides us the semanage
command on CentOS/RHEL
yum whatprovides semanage
# or
dnf whatprovides semanage
Linux netstat see the top connections of process
netstat -anp | awk '{print $7}' |sort | uniq -c | sort -k1 -nr
Linux netstat see the top connections of peers
netstat -nat|awk '{print$5}'|awk -F : '{print$1}'|sort|uniq -c|sort -rn
use openssl generate random bytes
# base64
openssl rand -base64 32
# or hex
openssl rand -hex 32
Fix terminal after displaying a binary file
# https://unix.stackexchange.com/questions/79684/fix-terminal-after-displaying-a-binary-file
alias reset='/usr/bin/reset; stty sane; tput rs1; clear; echo -e "\033c"'
查看服务日志
journalctl -u service-name -o cat -e # 查看日志
journalctl -u service-name -o cat -f # 实时日志
referer to: https://unix.stackexchange.com/questions/79684/fix-terminal-after-displaying-a-binary-file/79686#79686
k3s
k3s kubectl get ns
k3s kubectl -n <NAMESPACE> get pods
# k3s kubectl -n <NAMESPACE> exec -ti <POD> bash
k3s kubectl exec -it <POD> -n <NAMESPACE> -- bash
k3s kubectl cp <NAMESPACE>/<POD>:/tmp/foo /tmp/bar
kubernetes
kubectl get ns
kubectl -n <NAMESPACE> get pods
kubectl exec -it <POD> -n <NAMESPACE> -- bash
kubectl exec -it <POD> -n <NAMESPACE> -- sh
# 注意:复制文件的时候,需要带完整路径,包括目的地址
kubectl cp -n <NAMESPACE> <POD>:tmp/foo /tmp/bar
docker
docker exec -it ix-gitea-gitea-1 bash
docker exec -it ix-gitea-postgres-1 bash
docker volume ls
docker volume inspect <volume_name>
docker volume rm <volume_name>
docker volume prune # remove unused volume, be careful