linux常用命令总结

记录一些linux容易忘的linux操作命令

systemctl

1
2
3
4
5
6
systemctl start xxx     // 开启服务
systemctl stop xxx // 停止服务
systemctl restart xxx // 重启服务
systemctl enable xxx // 设置服务开机自启
systemctl disable xxx // 取消服务开机自启
systemctl status xxx // 查看服务运行状态

查看当前公网ip

1
2
3
4
5
6
7
curl icanhazip.com  
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/i

端口查看

1
2
lsof -i -P # 查看所有端口被占用情况
netstat -anp |grep [port] # 查看端口port被那个进程占用

刷新dns缓存

1
2
sudo apt-get install nscd
sudo /etc/init.d/nscd restart

其他命令

1
2
3
4
5
/etc/init.d/ssh start
cat /proc/version
export PATH="$PATH:/xxx"
du -hs # 查看某个文件夹占用大小
echo $SHELL && echo $0 # 查看当前终端类型

一些常见包

ubuntu

1
2
3
4
apt-get install lsb-release -y # lsb_release -a
apt-get install net-tools -y # ifconfig
apt-get install inetutils-ping -y #ping www.baidu.com
apt-get install aria2 -y

必备组件:

1
vim curl wget git lsb-release net-tools inetutils-ping tree lsof unzip zip socat

进程符号

1
2
3
4
5
6
7
8
9
10
11
12
R    正在运行,或在队列中的进程
S    处于休眠状态
T    停止或被追踪
Z    僵尸进程
W    进入内存交换(从内核2.6开始无效)
X    死掉的进程
<    高优先级
N    低优先级
L    有些页被锁进内存
s    包含子进程
+    位于后台的进程组;
l    多线程,克隆线程  

开启BBR加速

若linux内核大于等于4.9,则直接用以下命令开启bbr加速:

1
2
3
4
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
lsmod | grep bbr

若出现如下包含tcp_bbr的字样,说明开启成功。

1
tcp_bbr                20480  1

docker安装

  1. docker安装

    1
    2
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
  2. docker-compose安装

    1
    2
    3
    curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

    注:1.29.2是目前最新版本,安装时进github项目查看最新release选择对应版本。

安装指定python版本

1
2
3
apt install software-properties-common
add-apt-repository ppa:deadsnakes/ppa # 添加deadsnakes PPA源
apt install python3.8 # 安装python3.8

参考:https://segmentfault.com/a/1190000021967408

压缩包相关

详见菜鸟教程

1
2
tar -zxvf 压缩文件名.tar.gz
tar -zcvf 压缩文件名 .tar.gz 被压缩文件名
1
2
3
4
5
6
7
8
9
*.tar 用 tar –xvf 解压
*.gz 用 gzip -d或者gunzip 解压
*.tar.gz和*.tgz 用 tar –xzf 解压
*.bz2 用 bzip2 -d或者用bunzip2 解压
*.tar.bz2用tar –xjf 解压
*.Z 用 uncompress 解压
*.tar.Z 用tar –xZf 解压
*.rar 用 unrar e解压
*.zip 用 unzip 解压