# 命令帮助信息
# man help info whatis which whereis apropos
man 123 man
# 文件管理
# stat file touch ln chown chmode mv cp rm ls ll pwd dir tree find
stat FILE
ln SRC TAR [-s]
chown 777 TAR
chmod USER:GROUP TAR
cp SRC TAR -r
mv SRC TAR
rm -rf TAR
ls -la
tree TAR -L LEVEL
update-alternatives --set iptables /usr/sbin/iptables-legacy # manage symbolic link
# 文件内容查看
# cat head tail more less grep vim
head CONTENT -n LINENUM
grep CONTENT -r DIR -n
man curl | grep \\-i -n -C 1
# 用户管理
# groups groupadd groupdel groupmod gpasswd useradd userdel usermod passwd su sudo
cat /etc/group
/etc/gshadow
cat /etc/passwd
/etc/shadow
/etc/sudoers
groups USER
groupadd -g GID GROUP
gpasswd -a|-d USER -A| ADMIN -M MEM
useradd USER -u 234 -g MAINGROUP -G GROUP1,GROUP2,..
usermod USER -a -G GROUP3,GROUP4,..
userdel USER -r
passwd [USER]
su - [USER]
# 文件压缩解压
# tar create volumn file zip tell execute
tar -cvf TARGET.tar TARGET
tar -zcvf TARGET.tar.gz TARGET
tar -tvf TARGET.tar
tar -ztvf TARGET.tar.gz
tar -xvf TARGET.tar -C DIR
tar -zxvf TARGET.tar.gz -C DIR
# gzip list decompress
gzip TARGET
gzip -l TARGET.gz
gzip -d TARGET.gz
# 系统管理
# lsb_release reboot exit shutdown ps kill mount umount systemctl service crontab
cat /proc/cpuinfo
head /proc/meminfo
reboot -w
shutdown -h now
ps aux | sort -nrk 3 | head -n 5
ps -e f
ps -ef | grep vim
kill -l
kill -9 PID
kill -9 -1
mount [-o loop] TARGET.iso /mnt
umount TARGET.iso
systemctl --help
systemctl status|list|start|stop|restart|enable|disable
systemctl start|stop|enable|disable mysql.service
systemctl list-units --type=service
systemctl status|stop|disable firewalld
iptables -i INPUT -p tcp --dport 22 -j accept
service network.service status|start
crontab CRON COMMAND
hostnamectl
# 网络管理
# curl wget ip hostname ifconfig route ssh ssh-keygen iptables
curl www.baidu.com -o TARGET -v # save
curl -L|--location www.youtube.com -v # redirect
curl -i|-I|--head www.baidu.com # show header
curl www.baidu.com --trace TARGET.txt # more details
curl www.baidu.com?name=xxx -X|--request GET -v
curl www.baidu.com -X POST --data "name=xxx" -v # send form
curl www.baidu.com --user-agent "[USER]" -v
curl www.baidu.com -c|--cookie-jar cookies -v # save cookies
curl www.baidu.com -b|--cookie cookies -v # send cookies
curl www.baidu.com --header "ContentType:application/json"
curl www.baidu.com --user root:root
curl https://baidu.com -k|--insecure -v # ignore ssl
curl https://youtube.com -x|--proxy http://localhost:7980 -v
wget https://www.baidu.com -m|--mirror --reject=gif|--accept=gif # download http or ftp site
wget https://www.baidu.com -c|--continue # breakpoint retry
wget -i|--input-file download.txt # download list
wget https://www.baidu.com -d|--debug -o|--output-file logfile # output debug info
ip link|address|route|rule|.. show # show device, ipaddr, route, route_rule
ip link set loopback0|[DIVICE] up|down|[ARGUMENTS..] # config device arguments
ip addr add|del IP/MASK dev DEVICE # set ip address of device
ip route show|list # list or show route info
ip route add IP/MASK|default via ROUTEIP dev DEVICE # set route gateway of sub ip network
ip route del IP/MASK|default # remove route gateway
ip route get IP # via route_ip through dev eht2 from src dev_ip
ip route flush cache # flush cache
ip -s|--statistics links
hostname
ifconfig
route
ssh user@hostname -p 22 # accept pubkey from remotehost
ssh-genkey # gen ssh pub and priv key
ssh-copy-id root@hostname # send pubkey to remotehost
ssh root@hostname 'mkdir -p .ssh & cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
ssh root@hostname -D 8080 # bind local forward port
ssh -L local_port:host2:host2_port host3 # local port forward on host1
ftp localhost:local_port
ssh -R remote_port:host2:host2_port host1 # remote port forward on host3
iptables -nvL --line-number
iptables -t [filter|nat|mangle|raw] -L [INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING]
iptables -A INPUT -p tcp --dport 22 -j REJECT # reject all tcp to port 22
iptables -I INPUT -s 173.168.16.0/24 -p tcp --dport 22 -j ACCEPT # accept all tcp from .. to port 22
iptables -D INPUT 2 # delete rule 2 in chain INPUT
# add nat rule to chain POSTROUTING in table nat
iptables -t nat -A POSTROUTING -o eth0 -s 196.128.1.0/24 -j SNAT --to-source 60.205.177.173
iptables -t nat -A PREROUTING -i eth0 -d 60.205.177.173 -p tcp --dport 800 -j DNAT --to-destination 196.128.1.3:80
host -a www.baidu.com # analyse dns system
nslookup 114.114.114.114 # lookup domain name info
netcat -zv 10.255.255.254 80 # scan port with tcp
netcat -uv 10.255.255.254 80 # scan port with udp
netcat -zv acme-v02.api.letsencrypt.org 443 -w 2
nc -lp 80 -v > node.tar.gz # server listening on port
nc -nv 172.0.0.3 80 < hello.tar.gz # client send to server
ping 8.8.8.8 -c 3 # icmp
traceroute 114.114.114.114 # route path
netstat -a|--all -l|--listening -s|--statistics -p|--programs -c|--continuous
netstat -u|--udp -t|--tcp -x|--unix
netstat --route|--interface|--group
sudo netstat -tunlp|grep 80 # 查看端口占用
sudo lsof -i :80
# 硬件管理
df -ah # system disk space usage
du -sh # file space usage
top # display linux processes
free -th # dispaly mem
iotop # dispaly
# 窗口管理
tmux new -s mywindow
tmux ls
tmux attach -t mywindow
tmux kill-session -t mywindow
tmux detach | Ctrl b + d
Ctrl b + ? | ( | ) # help | switch to next window
Ctrl b + % | : | x # split left&right | split up&down | close current pane
Ctrl b + { | } # swap with last/next pane
Ctrl b + :set -g mouse on