常用的linux命令 2 years ago
# 返回上次的目录
cd -
# 切换到root用户
su
# 切换到其他用户
su username
#
#( 强制用A覆盖B)
sudo ln -sf A B
#eg: sudo ln -sf /home/bmk/node-v22.11.0-linux-x64/bin/node /usr/bin/node
#查看网络服务情况
netstat -anp | grep 80
# 设置ipv6路由
sudo ip -family inet6 route add default via fe80::6802:b8ff:febd:xxxx dev 网卡名
#查看eth0的MAC地址 DHCP静态ip设置会用到
cat /sys/class/net/eth0/address
# 查看当前目录下的所有文件列表
ls -al
ls -alt # 按时间排序: 时间最近的在前面
ls -altr # 按时间反向排序: 时间最近的在后面
# 查看盘符
sudo fdisk -l
# 查看磁盘使用情况
sudo df -h
# 把/xxx/xxx 挂载到 /some/dir
sudo mount /xxx/xxx /some/dir
# 查看关于a的进程
ps -ef |grep a
ps -p pid -v
# kill process
kill pid
# 检测流量
sudo iftop
# 查看当前主机状态
top
# 添加用户xxx
sudo adduser xxx
# 把xxx用户添加到sudo group中
sudo usermod -aG sudo xxx
sudo chown -R xxx:xxx /some/dir
# update passwd
sudo passwd username
nc -z host port # 如果有返回则表示此端口有服务
# tcp port: 查看tcp service
netstat -tuna | grep LISTEN
#使用ps命令找出占用内存资源最多的20个进程(数量可以任意设置)
ps aux | head -1;ps aux |grep -v PID |sort -rn -k +4 | head -20
# 检测端口是否可通
nc -v host port
eg:
查看文件大小
# 方法1
du -sh *
du -sh filename
# 方法2
ls -lht
查看某一端口下的后台信息
lsof -i :port
比如:nextjs的3000端口
这时你就可以通过kill pid的形式把进程给干掉
如何查看内存使用率
top
如何查看分区情况
lsblk
如何查看cpu负载量
uptime
参数解析:
- 14days:表示机器从开机到现在的运行时间
- 2 users:总共有2个终端登录
load average: 0.08, 0.14, 0.15
: 这3个数分别表示1min 5min 15min 的cpu负载;
如果数值超过1,怎么解读?
如: 1.08, 2.14, 0.15?
- 1.00 1core=100%
- 2.00 2core=100%
如何查看cpu核心呢?
方法1: 输入lscpu
就可以看到
方法2: top
后按下1
如何查看网卡的流量
ifconfig
RX
表开机到现在received的总流量TX
表开机到现在transfer的总流量ether
: mac地址broadcast
:广播地址netmask
:掩码
如何检测试网络联通性
ping
后面的time表示延迟
那ttl是什么意思呢?
“TTL”, or “time to live”. TTL is a bit of data kept with every packet, indicating how many more routers, or hops, it is allowed to pass between before expiring. For every router a packet passes through, this TTL value will be decreased by 1. When the value reaches zero, the router handling that packet will drop the packet and will send a warning message back to the sender, letting them know the TTL expired.
“ TTL”表示“生存时间”。TTL 是保存在每个数据包中的一段数据,指示在过期之前允许在两个数据包之间传递多少路由器或跃点。对于数据包通过的每个路由器,这个 TTL 值将减少1。当该值达到零时,处理该数据包的路由器将丢弃该数据包,并向发送方发送一条警告消息,让发送方知道 TTL 过期。
如何给网卡配置一个固定的ip地址
如果是centos的话,有3种可行的方法
1, vim
只需编辑这个文件即可: /etc/sysconfig/network-scripts/ifcfg-ens32
然后修改:
最后重启网络:
systemctl restart network
2, nmtui
这个是有gui图形界面的,按照指示操作,完事后别忘记重启网络
3,nmcli
- 上一篇: linux exit code
- 下一篇: linux下查看所有用户及所有用户组