Linux Usage

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"'

referer to: https://unix.stackexchange.com/questions/79684/fix-terminal-after-displaying-a-binary-file/79686#79686